home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / i386 / i386.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  86KB  |  3,226 lines

  1. /* Subroutines for insn-output.c for Intel X86.
  2.    Copyright (C) 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include <setjmp.h>
  23. #include <ctype.h>
  24. #include "config.h"
  25. #include "rtl.h"
  26. #include "regs.h"
  27. #include "hard-reg-set.h"
  28. #include "real.h"
  29. #include "insn-config.h"
  30. #include "conditions.h"
  31. #include "insn-flags.h"
  32. #include "output.h"
  33. #include "insn-attr.h"
  34. #include "tree.h"
  35. #include "flags.h"
  36. #include "function.h"
  37.  
  38. #ifdef EXTRA_CONSTRAINT
  39. /* If EXTRA_CONSTRAINT is defined, then the 'S'
  40.    constraint in REG_CLASS_FROM_LETTER will no longer work, and various
  41.    asm statements that need 'S' for class SIREG will break.  */
  42.  error EXTRA_CONSTRAINT conflicts with S constraint letter
  43. /* The previous line used to be #error, but some compilers barf
  44.    even if the conditional was untrue.  */
  45. #endif
  46.  
  47. #define AT_BP(mode) (gen_rtx (MEM, (mode), frame_pointer_rtx))
  48.  
  49. extern FILE *asm_out_file;
  50. extern char *strcat ();
  51.  
  52. char *singlemove_string ();
  53. char *output_move_const_single ();
  54. char *output_fp_cc0_set ();
  55.  
  56. char *hi_reg_name[] = HI_REGISTER_NAMES;
  57. char *qi_reg_name[] = QI_REGISTER_NAMES;
  58. char *qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
  59.  
  60. /* Array of the smallest class containing reg number REGNO, indexed by
  61.    REGNO.  Used by REGNO_REG_CLASS in i386.h. */
  62.  
  63. enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] =
  64. {
  65.   /* ax, dx, cx, bx */
  66.   AREG, DREG, CREG, BREG,
  67.   /* si, di, bp, sp */
  68.   SIREG, DIREG, INDEX_REGS, GENERAL_REGS,
  69.   /* FP registers */
  70.   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
  71.   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,       
  72.   /* arg pointer */
  73.   INDEX_REGS
  74. };
  75.  
  76. /* Test and compare insns in i386.md store the information needed to
  77.    generate branch and scc insns here.  */
  78.  
  79. struct rtx_def *i386_compare_op0 = NULL_RTX;
  80. struct rtx_def *i386_compare_op1 = NULL_RTX;
  81. struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)();
  82.  
  83. /* Register allocation order */
  84. char *i386_reg_alloc_order;
  85. static char regs_allocated[FIRST_PSEUDO_REGISTER];
  86.  
  87. /* # of registers to use to pass arguments. */
  88. char *i386_regparm_string;            /* # registers to use to pass args */
  89. int i386_regparm;                /* i386_regparm_string as a number */
  90.  
  91. /* Alignment to use for loops and jumps */
  92. char *i386_align_loops_string;            /* power of two alignment for loops */
  93. char *i386_align_jumps_string;            /* power of two alignment for non-loop jumps */
  94. char *i386_align_funcs_string;            /* power of two alignment for functions */
  95.  
  96. int i386_align_loops;                /* power of two alignment for loops */
  97. int i386_align_jumps;                /* power of two alignment for non-loop jumps */
  98. int i386_align_funcs;                /* power of two alignment for functions */
  99.  
  100.  
  101. /* Sometimes certain combinations of command options do not make
  102.    sense on a particular target machine.  You can define a macro
  103.    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
  104.    defined, is executed once just after all the command options have
  105.    been parsed.
  106.  
  107.    Don't use this macro to turn on various extra optimizations for
  108.    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
  109.  
  110. void
  111. override_options ()
  112. {
  113.   int ch, i, regno;
  114.   char *p;
  115.   int def_align;
  116.  
  117. #ifdef SUBTARGET_OVERRIDE_OPTIONS
  118.   SUBTARGET_OVERRIDE_OPTIONS;
  119. #endif
  120.  
  121.   /* Validate registers in register allocation order */
  122.   if (i386_reg_alloc_order)
  123.     {
  124.       for (i = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
  125.     {
  126.       switch (ch)
  127.         {
  128.         case 'a':    regno = 0;    break;
  129.         case 'd':    regno = 1;    break;
  130.         case 'c':    regno = 2;    break;
  131.         case 'b':    regno = 3;    break;
  132.         case 'S':    regno = 4;    break;
  133.         case 'D':    regno = 5;    break;
  134.         case 'B':    regno = 6;    break;
  135.  
  136.         default:    fatal ("Register '%c' is unknown", ch);
  137.         }
  138.  
  139.       if (regs_allocated[regno])
  140.         fatal ("Register '%c' was already specified in the allocation order", ch);
  141.  
  142.       regs_allocated[regno] = 1;
  143.     }
  144.     }
  145.  
  146.   /* Validate -mregparm= value */
  147.   if (i386_regparm_string)
  148.     {
  149.       i386_regparm = atoi (i386_regparm_string);
  150.       if (i386_regparm < 0 || i386_regparm > REGPARM_MAX)
  151.     fatal ("-mregparm=%d is not between 0 and %d", i386_regparm, REGPARM_MAX);
  152.     }
  153.  
  154.   def_align = (TARGET_386) ? 2 : 4;
  155.  
  156.   /* Validate -malign-loops= value, or provide default */
  157.   if (i386_align_loops_string)
  158.     {
  159.       i386_align_loops = atoi (i386_align_loops_string);
  160.       if (i386_align_loops < 0 || i386_align_loops > MAX_CODE_ALIGN)
  161.     fatal ("-malign-loops=%d is not between 0 and %d",
  162.            i386_align_loops, MAX_CODE_ALIGN);
  163.     }
  164.   else
  165.     i386_align_loops = 2;
  166.  
  167.   /* Validate -malign-jumps= value, or provide default */
  168.   if (i386_align_jumps_string)
  169.     {
  170.       i386_align_jumps = atoi (i386_align_jumps_string);
  171.       if (i386_align_jumps < 0 || i386_align_jumps > MAX_CODE_ALIGN)
  172.     fatal ("-malign-jumps=%d is not between 0 and %d",
  173.            i386_align_jumps, MAX_CODE_ALIGN);
  174.     }
  175.   else
  176.     i386_align_jumps = def_align;
  177.  
  178.   /* Validate -malign-functions= value, or provide default */
  179.   if (i386_align_funcs_string)
  180.     {
  181.       i386_align_funcs = atoi (i386_align_funcs_string);
  182.       if (i386_align_funcs < 0 || i386_align_funcs > MAX_CODE_ALIGN)
  183.     fatal ("-malign-functions=%d is not between 0 and %d",
  184.            i386_align_funcs, MAX_CODE_ALIGN);
  185.     }
  186.   else
  187.     i386_align_funcs = def_align;
  188. }
  189.  
  190. /* A C statement (sans semicolon) to choose the order in which to
  191.    allocate hard registers for pseudo-registers local to a basic
  192.    block.
  193.  
  194.    Store the desired register order in the array `reg_alloc_order'.
  195.    Element 0 should be the register to allocate first; element 1, the
  196.    next register; and so on.
  197.  
  198.    The macro body should not assume anything about the contents of
  199.    `reg_alloc_order' before execution of the macro.
  200.  
  201.    On most machines, it is not necessary to define this macro.  */
  202.  
  203. void
  204. order_regs_for_local_alloc ()
  205. {
  206.   int i, ch, order, regno;
  207.  
  208.   /* User specified the register allocation order */
  209.   if (i386_reg_alloc_order)
  210.     {
  211.       for (i = order = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++)
  212.     {
  213.       switch (ch)
  214.         {
  215.         case 'a':    regno = 0;    break;
  216.         case 'd':    regno = 1;    break;
  217.         case 'c':    regno = 2;    break;
  218.         case 'b':    regno = 3;    break;
  219.         case 'S':    regno = 4;    break;
  220.         case 'D':    regno = 5;    break;
  221.         case 'B':    regno = 6;    break;
  222.         }
  223.  
  224.       reg_alloc_order[order++] = regno;
  225.     }
  226.  
  227.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  228.     {
  229.       if (!regs_allocated[i])
  230.         reg_alloc_order[order++] = i;
  231.     }
  232.     }
  233.  
  234.   /* If users did not specify a register allocation order, favor eax
  235.      normally except if DImode variables are used, in which case
  236.      favor edx before eax, which seems to cause less spill register
  237.      not found messages.  */
  238.   else
  239.     {
  240.       rtx insn;
  241.  
  242.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  243.     reg_alloc_order[i] = i;
  244.  
  245.       if (optimize)
  246.     {
  247.       int use_dca = FALSE;
  248.  
  249.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  250.         {
  251.           if (GET_CODE (insn) == INSN)
  252.         {
  253.           rtx set = NULL_RTX;
  254.           rtx pattern = PATTERN (insn);
  255.  
  256.           if (GET_CODE (pattern) == SET)
  257.             set = pattern;
  258.  
  259.           else if ((GET_CODE (pattern) == PARALLEL
  260.                 || GET_CODE (pattern) == SEQUENCE)
  261.                && GET_CODE (XVECEXP (pattern, 0, 0)) == SET)
  262.             set = XVECEXP (pattern, 0, 0);
  263.  
  264.           if (set && GET_MODE (SET_SRC (set)) == DImode)
  265.             {
  266.               use_dca = TRUE;
  267.               break;
  268.             }
  269.         }
  270.         }
  271.  
  272.       if (use_dca)
  273.         {
  274.           reg_alloc_order[0] = 1;    /* edx */
  275.           reg_alloc_order[1] = 2;    /* ecx */
  276.           reg_alloc_order[2] = 0;    /* eax */
  277.         }
  278.     }
  279.     }
  280. }
  281.  
  282.  
  283. /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
  284.    attribute for DECL.  The attributes in ATTRIBUTES have previously been
  285.    assigned to DECL.  */
  286.  
  287. int
  288. i386_valid_decl_attribute_p (decl, attributes, identifier, args)
  289.      tree decl;
  290.      tree attributes;
  291.      tree identifier;
  292.      tree args;
  293. {
  294.   return 0;
  295. }
  296.  
  297. /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific
  298.    attribute for TYPE.  The attributes in ATTRIBUTES have previously been
  299.    assigned to TYPE.  */
  300.  
  301. int
  302. i386_valid_type_attribute_p (type, attributes, identifier, args)
  303.      tree type;
  304.      tree attributes;
  305.      tree identifier;
  306.      tree args;
  307. {
  308.   if (TREE_CODE (type) != FUNCTION_TYPE
  309.       && TREE_CODE (type) != FIELD_DECL
  310.       && TREE_CODE (type) != TYPE_DECL)
  311.     return 0;
  312.  
  313.   /* Stdcall attribute says callee is responsible for popping arguments
  314.      if they are not variable.  */
  315.   if (is_attribute_p ("stdcall", identifier))
  316.     return (args == NULL_TREE);
  317.  
  318.   /* Cdecl attribute says the callee is a normal C declaration */
  319.   if (is_attribute_p ("cdecl", identifier))
  320.     return (args == NULL_TREE);
  321.  
  322.   /* Regparm attribute specifies how many integer arguments are to be
  323.      passed in registers */
  324.   if (is_attribute_p ("regparm", identifier))
  325.     {
  326.       tree cst;
  327.  
  328.       if (!args || TREE_CODE (args) != TREE_LIST
  329.       || TREE_CHAIN (args) != NULL_TREE
  330.       || TREE_VALUE (args) == NULL_TREE)
  331.     return 0;
  332.  
  333.       cst = TREE_VALUE (args);
  334.       if (TREE_CODE (cst) != INTEGER_CST)
  335.     return 0;
  336.  
  337.       if (TREE_INT_CST_HIGH (cst) != 0
  338.       || TREE_INT_CST_LOW (cst) < 0
  339.       || TREE_INT_CST_LOW (cst) > REGPARM_MAX)
  340.     return 0;
  341.  
  342.       return 1;
  343.     }
  344.  
  345.   return 0;
  346. }
  347.  
  348. /* Return 0 if the attributes for two types are incompatible, 1 if they
  349.    are compatible, and 2 if they are nearly compatible (which causes a
  350.    warning to be generated).  */
  351.  
  352. int
  353. i386_comp_type_attributes (type1, type2)
  354.      tree type1;
  355.      tree type2;
  356. {
  357.   return 1;
  358. }
  359.  
  360.  
  361. /* Value is the number of bytes of arguments automatically
  362.    popped when returning from a subroutine call.
  363.    FUNDECL is the declaration node of the function (as a tree),
  364.    FUNTYPE is the data type of the function (as a tree),
  365.    or for a library call it is an identifier node for the subroutine name.
  366.    SIZE is the number of bytes of arguments passed on the stack.
  367.  
  368.    On the 80386, the RTD insn may be used to pop them if the number
  369.      of args is fixed, but if the number is variable then the caller
  370.      must pop them all.  RTD can't be used for library calls now
  371.      because the library is compiled with the Unix compiler.
  372.    Use of RTD is a selectable option, since it is incompatible with
  373.    standard Unix calling sequences.  If the option is not selected,
  374.    the caller must always pop the args.
  375.  
  376.    The attribute stdcall is equivalent to RTD on a per module basis.  */
  377.  
  378. int
  379. i386_return_pops_args (fundecl, funtype, size)
  380.      tree fundecl;
  381.      tree funtype;
  382.      int size;
  383. {
  384.   int rtd = TARGET_RTD;
  385.  
  386.   if (TREE_CODE (funtype) == IDENTIFIER_NODE)
  387.     return 0;
  388.  
  389.   if (fundecl && TREE_CODE_CLASS (TREE_CODE (fundecl)) == 'd')
  390.     {
  391.       /* Cdecl functions override -mrtd, and never pop the stack */
  392.       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype)))
  393.     return 0;
  394.  
  395.       /* Stdcall functions will pop the stack if not variable args */
  396.       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype)))
  397.     rtd = 1;
  398.     }
  399.  
  400.   if (rtd)
  401.     {
  402.       if (TYPE_ARG_TYPES (funtype) == NULL_TREE
  403.       || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype))) == void_type_node))
  404.     return size;
  405.  
  406.       if (aggregate_value_p (TREE_TYPE (funtype)))
  407.     return GET_MODE_SIZE (Pmode);
  408.     }
  409.  
  410.   return 0;
  411. }
  412.  
  413.  
  414. /* Argument support functions.  */
  415.  
  416. /* Initialize a variable CUM of type CUMULATIVE_ARGS
  417.    for a call to a function whose data type is FNTYPE.
  418.    For a library call, FNTYPE is 0.  */
  419.  
  420. void
  421. init_cumulative_args (cum, fntype, libname)
  422.      CUMULATIVE_ARGS *cum;    /* argument info to initialize */
  423.      tree fntype;        /* tree ptr for function decl */
  424.      rtx libname;        /* SYMBOL_REF of library name or 0 */
  425. {
  426.   static CUMULATIVE_ARGS zero_cum;
  427.   tree param, next_param;
  428.  
  429.   if (TARGET_DEBUG_ARG)
  430.     {
  431.       fprintf (stderr, "\ninit_cumulative_args (");
  432.       if (fntype)
  433.     {
  434.       tree ret_type = TREE_TYPE (fntype);
  435.       fprintf (stderr, "fntype code = %s, ret code = %s",
  436.            tree_code_name[ (int)TREE_CODE (fntype) ],
  437.            tree_code_name[ (int)TREE_CODE (ret_type) ]);
  438.     }
  439.       else
  440.     fprintf (stderr, "no fntype");
  441.  
  442.       if (libname)
  443.     fprintf (stderr, ", libname = %s", XSTR (libname, 0));
  444.     }
  445.  
  446.   *cum = zero_cum;
  447.  
  448.   /* Set up the number of registers to use for passing arguments.  */
  449.   cum->nregs = i386_regparm;
  450.   if (fntype)
  451.     {
  452.       tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype));
  453.       if (attr)
  454.     cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
  455.     }
  456.  
  457.   /* Determine if this function has variable arguments.  This is
  458.      indicated by the last argument being 'void_type_mode' if there
  459.      are no variable arguments.  If there are variable arguments, then
  460.      we won't pass anything in registers */
  461.  
  462.   if (cum->nregs)
  463.     {
  464.       for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
  465.        param != (tree)0;
  466.        param = next_param)
  467.     {
  468.       next_param = TREE_CHAIN (param);
  469.       if (next_param == (tree)0 && TREE_VALUE (param) != void_type_node)
  470.         cum->nregs = 0;
  471.     }
  472.     }
  473.  
  474.   if (TARGET_DEBUG_ARG)
  475.     fprintf (stderr, ", nregs=%d )\n", cum->nregs);
  476.  
  477.   return;
  478. }
  479.  
  480. /* Update the data in CUM to advance over an argument
  481.    of mode MODE and data type TYPE.
  482.    (TYPE is null for libcalls where that information may not be available.)  */
  483.  
  484. void
  485. function_arg_advance (cum, mode, type, named)
  486.      CUMULATIVE_ARGS *cum;    /* current arg information */
  487.      enum machine_mode mode;    /* current arg mode */
  488.      tree type;            /* type of the argument or 0 if lib support */
  489.      int named;            /* whether or not the argument was named */
  490. {
  491.   int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  492.   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  493.  
  494.   if (TARGET_DEBUG_ARG)
  495.     fprintf (stderr,
  496.          "function_adv( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d )\n\n",
  497.          words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
  498.  
  499.   cum->words += words;
  500.   cum->nregs -= words;
  501.   cum->regno += words;
  502.  
  503.   if (cum->nregs <= 0)
  504.     {
  505.       cum->nregs = 0;
  506.       cum->regno = 0;
  507.     }
  508.  
  509.   return;
  510. }
  511.  
  512. /* Define where to put the arguments to a function.
  513.    Value is zero to push the argument on the stack,
  514.    or a hard register in which to store the argument.
  515.  
  516.    MODE is the argument's machine mode.
  517.    TYPE is the data type of the argument (as a tree).
  518.     This is null for libcalls where that information may
  519.     not be available.
  520.    CUM is a variable of type CUMULATIVE_ARGS which gives info about
  521.     the preceding args and about the function being called.
  522.    NAMED is nonzero if this argument is a named parameter
  523.     (otherwise it is an extra parameter matching an ellipsis).  */
  524.  
  525. struct rtx_def *
  526. function_arg (cum, mode, type, named)
  527.      CUMULATIVE_ARGS *cum;    /* current arg information */
  528.      enum machine_mode mode;    /* current arg mode */
  529.      tree type;            /* type of the argument or 0 if lib support */
  530.      int named;            /* != 0 for normal args, == 0 for ... args */
  531. {
  532.   rtx ret   = NULL_RTX;
  533.   int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  534.   int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  535.  
  536.   switch (mode)
  537.     {
  538.     default:            /* for now, pass fp/complex values on the stack */
  539.       break;
  540.  
  541.     case BLKmode:
  542.     case DImode:
  543.     case SImode:
  544.     case HImode:
  545.     case QImode:
  546.       if (words <= cum->nregs)
  547.     ret = gen_rtx (REG, mode, cum->regno);
  548.       break;
  549.     }
  550.  
  551.   if (TARGET_DEBUG_ARG)
  552.     {
  553.       fprintf (stderr,
  554.            "function_arg( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d",
  555.            words, cum->words, cum->nregs, GET_MODE_NAME (mode), named);
  556.  
  557.       if (ret)
  558.     fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]);
  559.       else
  560.     fprintf (stderr, ", stack");
  561.  
  562.       fprintf (stderr, " )\n");
  563.     }
  564.  
  565.   return ret;
  566. }
  567.  
  568. /* For an arg passed partly in registers and partly in memory,
  569.    this is the number of registers used.
  570.    For args passed entirely in registers or entirely in memory, zero.  */
  571.  
  572. int
  573. function_arg_partial_nregs (cum, mode, type, named)
  574.      CUMULATIVE_ARGS *cum;    /* current arg information */
  575.      enum machine_mode mode;    /* current arg mode */
  576.      tree type;            /* type of the argument or 0 if lib support */
  577.      int named;            /* != 0 for normal args, == 0 for ... args */
  578. {
  579.   return 0;
  580. }
  581.  
  582.  
  583. /* Output an insn whose source is a 386 integer register.  SRC is the
  584.    rtx for the register, and TEMPLATE is the op-code template.  SRC may
  585.    be either SImode or DImode.
  586.  
  587.    The template will be output with operands[0] as SRC, and operands[1]
  588.    as a pointer to the top of the 386 stack.  So a call from floatsidf2
  589.    would look like this:
  590.  
  591.       output_op_from_reg (operands[1], AS1 (fild%z0,%1));
  592.  
  593.    where %z0 corresponds to the caller's operands[1], and is used to
  594.    emit the proper size suffix.
  595.  
  596.    ??? Extend this to handle HImode - a 387 can load and store HImode
  597.    values directly. */
  598.  
  599. void
  600. output_op_from_reg (src, template)
  601.      rtx src;
  602.      char *template;
  603. {
  604.   rtx xops[4];
  605.   int size = GET_MODE_SIZE (GET_MODE (src));
  606.  
  607.   xops[0] = src;
  608.   xops[1] = AT_SP (Pmode);
  609.   xops[2] = GEN_INT (size);
  610.   xops[3] = stack_pointer_rtx;
  611.  
  612.   if (size > UNITS_PER_WORD)
  613.     {
  614.       rtx high;
  615.       if (size > 2 * UNITS_PER_WORD)
  616.     {
  617.       high = gen_rtx (REG, SImode, REGNO (src) + 2);
  618.       output_asm_insn (AS1 (push%L0,%0), &high);
  619.     }
  620.       high = gen_rtx (REG, SImode, REGNO (src) + 1);
  621.       output_asm_insn (AS1 (push%L0,%0), &high);
  622.     }
  623.   output_asm_insn (AS1 (push%L0,%0), &src);
  624.  
  625.   output_asm_insn (template, xops);
  626.  
  627.   output_asm_insn (AS2 (add%L3,%2,%3), xops);
  628. }
  629.  
  630. /* Output an insn to pop an value from the 387 top-of-stack to 386
  631.    register DEST. The 387 register stack is popped if DIES is true.  If
  632.    the mode of DEST is an integer mode, a `fist' integer store is done,
  633.    otherwise a `fst' float store is done. */
  634.  
  635. void
  636. output_to_reg (dest, dies)
  637.      rtx dest;
  638.      int dies;
  639. {
  640.   rtx xops[4];
  641.   int size = GET_MODE_SIZE (GET_MODE (dest));
  642.  
  643.   xops[0] = AT_SP (Pmode);
  644.   xops[1] = stack_pointer_rtx;
  645.   xops[2] = GEN_INT (size);
  646.   xops[3] = dest;
  647.  
  648.   output_asm_insn (AS2 (sub%L1,%2,%1), xops);
  649.  
  650.   if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_INT)
  651.     {
  652.       if (dies)
  653.     output_asm_insn (AS1 (fistp%z3,%y0), xops);
  654.       else
  655.     output_asm_insn (AS1 (fist%z3,%y0), xops);
  656.     }
  657.   else if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_FLOAT)
  658.     {
  659.       if (dies)
  660.     output_asm_insn (AS1 (fstp%z3,%y0), xops);
  661.       else
  662.     {
  663.       if (GET_MODE (dest) == XFmode)
  664.         {
  665.           output_asm_insn (AS1 (fstp%z3,%y0), xops);
  666.           output_asm_insn (AS1 (fld%z3,%y0), xops);
  667.         }
  668.       else
  669.         output_asm_insn (AS1 (fst%z3,%y0), xops);
  670.     }
  671.     }
  672.   else
  673.     abort ();
  674.  
  675.   output_asm_insn (AS1 (pop%L0,%0), &dest);
  676.  
  677.   if (size > UNITS_PER_WORD)
  678.     {
  679.       dest = gen_rtx (REG, SImode, REGNO (dest) + 1);
  680.       output_asm_insn (AS1 (pop%L0,%0), &dest);
  681.       if (size > 2 * UNITS_PER_WORD)
  682.     {
  683.       dest = gen_rtx (REG, SImode, REGNO (dest) + 1);
  684.       output_asm_insn (AS1 (pop%L0,%0), &dest);
  685.     }
  686.     }
  687. }
  688.  
  689. char *
  690. singlemove_string (operands)
  691.      rtx *operands;
  692. {
  693.   rtx x;
  694.   if (GET_CODE (operands[0]) == MEM
  695.       && GET_CODE (x = XEXP (operands[0], 0)) == PRE_DEC)
  696.     {
  697.       if (XEXP (x, 0) != stack_pointer_rtx)
  698.     abort ();
  699.       return "push%L1 %1";
  700.     }
  701.   else if (GET_CODE (operands[1]) == CONST_DOUBLE)
  702.     {
  703.       return output_move_const_single (operands);
  704.     }
  705.   else if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == REG)
  706.     return AS2 (mov%L0,%1,%0);
  707.   else if (CONSTANT_P (operands[1]))
  708.     return AS2 (mov%L0,%1,%0);
  709.   else
  710.     {
  711.       output_asm_insn ("push%L1 %1", operands);
  712.       return "pop%L0 %0";
  713.     }
  714. }
  715.  
  716. /* Return a REG that occurs in ADDR with coefficient 1.
  717.    ADDR can be effectively incremented by incrementing REG.  */
  718.  
  719. static rtx
  720. find_addr_reg (addr)
  721.      rtx addr;
  722. {
  723.   while (GET_CODE (addr) == PLUS)
  724.     {
  725.       if (GET_CODE (XEXP (addr, 0)) == REG)
  726.     addr = XEXP (addr, 0);
  727.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  728.     addr = XEXP (addr, 1);
  729.       else if (CONSTANT_P (XEXP (addr, 0)))
  730.     addr = XEXP (addr, 1);
  731.       else if (CONSTANT_P (XEXP (addr, 1)))
  732.     addr = XEXP (addr, 0);
  733.       else
  734.     abort ();
  735.     }
  736.   if (GET_CODE (addr) == REG)
  737.     return addr;
  738.   abort ();
  739. }
  740.  
  741.  
  742. /* Output an insn to add the constant N to the register X.  */
  743.  
  744. static void
  745. asm_add (n, x)
  746.      int n;
  747.      rtx x;
  748. {
  749.   rtx xops[2];
  750.   xops[0] = x;
  751.  
  752.   if (n == -1)
  753.     output_asm_insn (AS1 (dec%L0,%0), xops);
  754.   else if (n == 1)
  755.     output_asm_insn (AS1 (inc%L0,%0), xops);
  756.   else if (n < 0)
  757.     {
  758.       xops[1] = GEN_INT (-n);
  759.       output_asm_insn (AS2 (sub%L0,%1,%0), xops);
  760.     }
  761.   else if (n > 0)
  762.     {
  763.       xops[1] = GEN_INT (n);
  764.       output_asm_insn (AS2 (add%L0,%1,%0), xops);
  765.     }
  766. }
  767.  
  768.  
  769. /* Output assembler code to perform a doubleword move insn
  770.    with operands OPERANDS.  */
  771.  
  772. char *
  773. output_move_double (operands)
  774.      rtx *operands;
  775. {
  776.   enum {REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1;
  777.   rtx latehalf[2];
  778.   rtx middlehalf[2];
  779.   rtx xops[2];
  780.   rtx addreg0 = 0, addreg1 = 0;
  781.   int dest_overlapped_low = 0;
  782.   int size = GET_MODE_SIZE (GET_MODE (operands[0]));
  783.  
  784.   middlehalf[0] = 0;
  785.   middlehalf[1] = 0;
  786.  
  787.   /* First classify both operands.  */
  788.  
  789.   if (REG_P (operands[0]))
  790.     optype0 = REGOP;
  791.   else if (offsettable_memref_p (operands[0]))
  792.     optype0 = OFFSOP;
  793.   else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
  794.     optype0 = POPOP;
  795.   else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
  796.     optype0 = PUSHOP;
  797.   else if (GET_CODE (operands[0]) == MEM)
  798.     optype0 = MEMOP;
  799.   else
  800.     optype0 = RNDOP;
  801.  
  802.   if (REG_P (operands[1]))
  803.     optype1 = REGOP;
  804.   else if (CONSTANT_P (operands[1]))
  805.     optype1 = CNSTOP;
  806.   else if (offsettable_memref_p (operands[1]))
  807.     optype1 = OFFSOP;
  808.   else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
  809.     optype1 = POPOP;
  810.   else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
  811.     optype1 = PUSHOP;
  812.   else if (GET_CODE (operands[1]) == MEM)
  813.     optype1 = MEMOP;
  814.   else
  815.     optype1 = RNDOP;
  816.  
  817.   /* Check for the cases that the operand constraints are not
  818.      supposed to allow to happen.  Abort if we get one,
  819.      because generating code for these cases is painful.  */
  820.  
  821.   if (optype0 == RNDOP || optype1 == RNDOP)
  822.     abort ();
  823.  
  824.   /* If one operand is decrementing and one is incrementing
  825.      decrement the former register explicitly
  826.      and change that operand into ordinary indexing.  */
  827.  
  828.   if (optype0 == PUSHOP && optype1 == POPOP)
  829.     {
  830.       /* ??? Can this ever happen on i386? */
  831.       operands[0] = XEXP (XEXP (operands[0], 0), 0);
  832.       asm_add (-size, operands[0]);
  833.       if (GET_MODE (operands[1]) == XFmode)
  834.         operands[0] = gen_rtx (MEM, XFmode, operands[0]);
  835.       else if (GET_MODE (operands[0]) == DFmode)
  836.         operands[0] = gen_rtx (MEM, DFmode, operands[0]);
  837.       else
  838.         operands[0] = gen_rtx (MEM, DImode, operands[0]);
  839.       optype0 = OFFSOP;
  840.     }
  841.  
  842.   if (optype0 == POPOP && optype1 == PUSHOP)
  843.     {
  844.       /* ??? Can this ever happen on i386? */
  845.       operands[1] = XEXP (XEXP (operands[1], 0), 0);
  846.       asm_add (-size, operands[1]);
  847.       if (GET_MODE (operands[1]) == XFmode)
  848.         operands[1] = gen_rtx (MEM, XFmode, operands[1]);
  849.       else if (GET_MODE (operands[1]) == DFmode)
  850.         operands[1] = gen_rtx (MEM, DFmode, operands[1]);
  851.       else
  852.         operands[1] = gen_rtx (MEM, DImode, operands[1]);
  853.       optype1 = OFFSOP;
  854.     }
  855.  
  856.   /* If an operand is an unoffsettable memory ref, find a register
  857.      we can increment temporarily to make it refer to the second word.  */
  858.  
  859.   if (optype0 == MEMOP)
  860.     addreg0 = find_addr_reg (XEXP (operands[0], 0));
  861.  
  862.   if (optype1 == MEMOP)
  863.     addreg1 = find_addr_reg (XEXP (operands[1], 0));
  864.  
  865.   /* Ok, we can do one word at a time.
  866.      Normally we do the low-numbered word first,
  867.      but if either operand is autodecrementing then we
  868.      do the high-numbered word first.
  869.  
  870.      In either case, set up in LATEHALF the operands to use
  871.      for the high-numbered word and in some cases alter the
  872.      operands in OPERANDS to be suitable for the low-numbered word.  */
  873.  
  874.   if (size == 12)
  875.     {
  876.       if (optype0 == REGOP)
  877.     {
  878.       middlehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  879.       latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 2);
  880.     }
  881.       else if (optype0 == OFFSOP)
  882.     {
  883.       middlehalf[0] = adj_offsettable_operand (operands[0], 4);
  884.       latehalf[0] = adj_offsettable_operand (operands[0], 8);
  885.     }
  886.       else
  887.     {
  888.          middlehalf[0] = operands[0];
  889.          latehalf[0] = operands[0];
  890.     }
  891.     
  892.       if (optype1 == REGOP)
  893.     {
  894.           middlehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  895.           latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 2);
  896.     }
  897.       else if (optype1 == OFFSOP)
  898.     {
  899.           middlehalf[1] = adj_offsettable_operand (operands[1], 4);
  900.           latehalf[1] = adj_offsettable_operand (operands[1], 8);
  901.     }
  902.       else if (optype1 == CNSTOP)
  903.     {
  904.       if (GET_CODE (operands[1]) == CONST_DOUBLE)
  905.         {
  906.           REAL_VALUE_TYPE r; long l[3];
  907.  
  908.           REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  909.           REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  910.           operands[1] = GEN_INT (l[0]);
  911.           middlehalf[1] = GEN_INT (l[1]);
  912.           latehalf[1] = GEN_INT (l[2]);
  913.         }
  914.       else if (CONSTANT_P (operands[1]))
  915.         /* No non-CONST_DOUBLE constant should ever appear here.  */
  916.         abort ();
  917.         }
  918.       else
  919.     {
  920.       middlehalf[1] = operands[1];
  921.       latehalf[1] = operands[1];
  922.     }
  923.     }
  924.   else /* size is not 12: */
  925.     {
  926.       if (optype0 == REGOP)
  927.     latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
  928.       else if (optype0 == OFFSOP)
  929.     latehalf[0] = adj_offsettable_operand (operands[0], 4);
  930.       else
  931.     latehalf[0] = operands[0];
  932.  
  933.       if (optype1 == REGOP)
  934.     latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
  935.       else if (optype1 == OFFSOP)
  936.     latehalf[1] = adj_offsettable_operand (operands[1], 4);
  937.       else if (optype1 == CNSTOP)
  938.     split_double (operands[1], &operands[1], &latehalf[1]);
  939.       else
  940.     latehalf[1] = operands[1];
  941.     }
  942.  
  943.   /* If insn is effectively movd N (sp),-(sp) then we will do the
  944.      high word first.  We should use the adjusted operand 1
  945.      (which is N+4 (sp) or N+8 (sp))
  946.      for the low word and middle word as well,
  947.      to compensate for the first decrement of sp.  */
  948.   if (optype0 == PUSHOP
  949.       && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
  950.       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
  951.     middlehalf[1] = operands[1] = latehalf[1];
  952.  
  953.   /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
  954.      if the upper part of reg N does not appear in the MEM, arrange to
  955.      emit the move late-half first.  Otherwise, compute the MEM address
  956.      into the upper part of N and use that as a pointer to the memory
  957.      operand.  */
  958.   if (optype0 == REGOP
  959.       && (optype1 == OFFSOP || optype1 == MEMOP))
  960.     {
  961.       if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
  962.       && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  963.     {
  964.       /* If both halves of dest are used in the src memory address,
  965.          compute the address into latehalf of dest.  */
  966. compadr:
  967.       xops[0] = latehalf[0];
  968.       xops[1] = XEXP (operands[1], 0);
  969.       output_asm_insn (AS2 (lea%L0,%a1,%0), xops);
  970.       if( GET_MODE (operands[1]) == XFmode )
  971.         {
  972. /*        abort (); */
  973.           operands[1] = gen_rtx (MEM, XFmode, latehalf[0]);
  974.           middlehalf[1] = adj_offsettable_operand (operands[1], size-8);
  975.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  976.         }
  977.       else
  978.         {
  979.           operands[1] = gen_rtx (MEM, DImode, latehalf[0]);
  980.           latehalf[1] = adj_offsettable_operand (operands[1], size-4);
  981.         }
  982.     }
  983.       else if (size == 12
  984.          && reg_mentioned_p (middlehalf[0], XEXP (operands[1], 0)))
  985.     {
  986.       /* Check for two regs used by both source and dest. */
  987.       if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
  988.         || reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
  989.         goto compadr;
  990.  
  991.       /* JRV says this can't happen: */
  992.       if (addreg0 || addreg1)
  993.           abort();
  994.  
  995.       /* Only the middle reg conflicts; simply put it last. */
  996.       output_asm_insn (singlemove_string (operands), operands);
  997.       output_asm_insn (singlemove_string (latehalf), latehalf);
  998.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  999.       return "";
  1000.     }
  1001.       else if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)))
  1002.     /* If the low half of dest is mentioned in the source memory
  1003.        address, the arrange to emit the move late half first.  */
  1004.     dest_overlapped_low = 1;
  1005.     }
  1006.  
  1007.   /* If one or both operands autodecrementing,
  1008.      do the two words, high-numbered first.  */
  1009.  
  1010.   /* Likewise,  the first move would clobber the source of the second one,
  1011.      do them in the other order.  This happens only for registers;
  1012.      such overlap can't happen in memory unless the user explicitly
  1013.      sets it up, and that is an undefined circumstance.  */
  1014.  
  1015. /*
  1016.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1017.       || (optype0 == REGOP && optype1 == REGOP
  1018.       && REGNO (operands[0]) == REGNO (latehalf[1]))
  1019.       || dest_overlapped_low)
  1020. */
  1021.   if (optype0 == PUSHOP || optype1 == PUSHOP
  1022.       || (optype0 == REGOP && optype1 == REGOP
  1023.       && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
  1024.           || REGNO (operands[0]) == REGNO (latehalf[1])))
  1025.       || dest_overlapped_low)
  1026.     {
  1027.       /* Make any unoffsettable addresses point at high-numbered word.  */
  1028.       if (addreg0)
  1029.     asm_add (size-4, addreg0);
  1030.       if (addreg1)
  1031.     asm_add (size-4, addreg1);
  1032.  
  1033.       /* Do that word.  */
  1034.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1035.  
  1036.       /* Undo the adds we just did.  */
  1037.       if (addreg0)
  1038.          asm_add (-4, addreg0);
  1039.       if (addreg1)
  1040.     asm_add (-4, addreg1);
  1041.  
  1042.       if (size == 12)
  1043.         {
  1044.         output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1045.         if (addreg0)
  1046.            asm_add (-4, addreg0);
  1047.         if (addreg1)
  1048.        asm_add (-4, addreg1);
  1049.     }
  1050.  
  1051.       /* Do low-numbered word.  */
  1052.       return singlemove_string (operands);
  1053.     }
  1054.  
  1055.   /* Normal case: do the two words, low-numbered first.  */
  1056.  
  1057.   output_asm_insn (singlemove_string (operands), operands);
  1058.  
  1059.   /* Do the middle one of the three words for long double */
  1060.   if (size == 12)
  1061.     {
  1062.       if (addreg0)
  1063.         asm_add (4, addreg0);
  1064.       if (addreg1)
  1065.         asm_add (4, addreg1);
  1066.  
  1067.       output_asm_insn (singlemove_string (middlehalf), middlehalf);
  1068.     }
  1069.  
  1070.   /* Make any unoffsettable addresses point at high-numbered word.  */
  1071.   if (addreg0)
  1072.     asm_add (4, addreg0);
  1073.   if (addreg1)
  1074.     asm_add (4, addreg1);
  1075.  
  1076.   /* Do that word.  */
  1077.   output_asm_insn (singlemove_string (latehalf), latehalf);
  1078.  
  1079.   /* Undo the adds we just did.  */
  1080.   if (addreg0)
  1081.     asm_add (4-size, addreg0);
  1082.   if (addreg1)
  1083.     asm_add (4-size, addreg1);
  1084.  
  1085.   return "";
  1086. }
  1087.  
  1088.  
  1089. #define MAX_TMPS 2        /* max temporary registers used */
  1090.  
  1091. /* Output the appropriate code to move push memory on the stack */
  1092.  
  1093. char *
  1094. output_move_pushmem (operands, insn, length, tmp_start, n_operands)
  1095.      rtx operands[];
  1096.      rtx insn;
  1097.      int length;
  1098.      int tmp_start;
  1099.      int n_operands;
  1100. {
  1101.  
  1102.   struct {
  1103.     char *load;
  1104.     char *push;
  1105.     rtx   xops[2];
  1106.   } tmp_info[MAX_TMPS];
  1107.  
  1108.   rtx src = operands[1];
  1109.   int max_tmps = 0;
  1110.   int offset = 0;
  1111.   int stack_p = reg_overlap_mentioned_p (stack_pointer_rtx, src);
  1112.   int stack_offset = 0;
  1113.   int i, num_tmps;
  1114.   rtx xops[1];
  1115.  
  1116.   if (!offsettable_memref_p (src))
  1117.     fatal_insn ("Source is not offsettable", insn);
  1118.  
  1119.   if ((length & 3) != 0)
  1120.     fatal_insn ("Pushing non-word aligned size", insn);
  1121.  
  1122.   /* Figure out which temporary registers we have available */
  1123.   for (i = tmp_start; i < n_operands; i++)
  1124.     {
  1125.       if (GET_CODE (operands[i]) == REG)
  1126.     {
  1127.       if (reg_overlap_mentioned_p (operands[i], src))
  1128.         continue;
  1129.  
  1130.       tmp_info[ max_tmps++ ].xops[1] = operands[i];
  1131.       if (max_tmps == MAX_TMPS)
  1132.         break;
  1133.     }
  1134.     }
  1135.  
  1136.   if (max_tmps == 0)
  1137.     for (offset = length - 4; offset >= 0; offset -= 4)
  1138.       {
  1139.     xops[0] = adj_offsettable_operand (src, offset + stack_offset);
  1140.     output_asm_insn (AS1(push%L0,%0), xops);
  1141.     if (stack_p)
  1142.       stack_offset += 4;
  1143.       }
  1144.  
  1145.   else
  1146.     for (offset = length - 4; offset >= 0; )
  1147.       {
  1148.     for (num_tmps = 0; num_tmps < max_tmps && offset >= 0; num_tmps++)
  1149.       {
  1150.         tmp_info[num_tmps].load    = AS2(mov%L0,%0,%1);
  1151.         tmp_info[num_tmps].push    = AS1(push%L0,%1);
  1152.         tmp_info[num_tmps].xops[0] = adj_offsettable_operand (src, offset + stack_offset);
  1153.         offset -= 4;
  1154.       }
  1155.  
  1156.     for (i = 0; i < num_tmps; i++)
  1157.       output_asm_insn (tmp_info[i].load, tmp_info[i].xops);
  1158.  
  1159.     for (i = 0; i < num_tmps; i++)
  1160.       output_asm_insn (tmp_info[i].push, tmp_info[i].xops);
  1161.  
  1162.     if (stack_p)
  1163.       stack_offset += 4*num_tmps;
  1164.       }
  1165.  
  1166.   return "";
  1167. }
  1168.  
  1169.  
  1170.  
  1171. /* Output the appropriate code to move data between two memory locations */
  1172.  
  1173. char *
  1174. output_move_memory (operands, insn, length, tmp_start, n_operands)
  1175.      rtx operands[];
  1176.      rtx insn;
  1177.      int length;
  1178.      int tmp_start;
  1179.      int n_operands;
  1180. {
  1181.   struct {
  1182.     char *load;
  1183.     char *store;
  1184.     rtx   xops[3];
  1185.   } tmp_info[MAX_TMPS];
  1186.  
  1187.   rtx dest = operands[0];
  1188.   rtx src  = operands[1];
  1189.   rtx qi_tmp = NULL_RTX;
  1190.   int max_tmps = 0;
  1191.   int offset = 0;
  1192.   int i, num_tmps;
  1193.   rtx xops[3];
  1194.  
  1195.   if (GET_CODE (dest) == MEM
  1196.       && GET_CODE (XEXP (dest, 0)) == PRE_INC
  1197.       && XEXP (XEXP (dest, 0), 0) == stack_pointer_rtx)
  1198.     return output_move_pushmem (operands, insn, length, tmp_start, n_operands);
  1199.  
  1200.   if (!offsettable_memref_p (src))
  1201.     fatal_insn ("Source is not offsettable", insn);
  1202.  
  1203.   if (!offsettable_memref_p (dest))
  1204.     fatal_insn ("Destination is not offsettable", insn);
  1205.  
  1206.   /* Figure out which temporary registers we have available */
  1207.   for (i = tmp_start; i < n_operands; i++)
  1208.     {
  1209.       if (GET_CODE (operands[i]) == REG)
  1210.     {
  1211.       if ((length & 1) != 0 && !qi_tmp && QI_REG_P (operands[i]))
  1212.         qi_tmp = operands[i];
  1213.  
  1214.       if (reg_overlap_mentioned_p (operands[i], dest))
  1215.         fatal_insn ("Temporary register overlaps the destination", insn);
  1216.  
  1217.       if (reg_overlap_mentioned_p (operands[i], src))
  1218.         fatal_insn ("Temporary register overlaps the source", insn);
  1219.  
  1220.       tmp_info[ max_tmps++ ].xops[2] = operands[i];
  1221.       if (max_tmps == MAX_TMPS)
  1222.         break;
  1223.     }
  1224.     }
  1225.  
  1226.   if (max_tmps == 0)
  1227.     fatal_insn ("No scratch registers were found to do memory->memory moves", insn);
  1228.  
  1229.   if ((length & 1) != 0)
  1230.     {
  1231.       if (!qi_tmp)
  1232.     fatal_insn ("No byte register found when moving odd # of bytes.", insn);
  1233.     }
  1234.  
  1235.   while (length > 1)
  1236.     {
  1237.       for (num_tmps = 0; num_tmps < max_tmps; num_tmps++)
  1238.     {
  1239.       if (length >= 4)
  1240.         {
  1241.           tmp_info[num_tmps].load    = AS2(mov%L0,%1,%2);
  1242.           tmp_info[num_tmps].store   = AS2(mov%L0,%2,%0);
  1243.           tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset);
  1244.           tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset);
  1245.           offset += 4;
  1246.           length -= 4;
  1247.         }
  1248.       else if (length >= 2)
  1249.         {
  1250.           tmp_info[num_tmps].load    = AS2(mov%W0,%1,%2);
  1251.           tmp_info[num_tmps].store   = AS2(mov%W0,%2,%0);
  1252.           tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset);
  1253.           tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset);
  1254.           offset += 2;
  1255.           length -= 2;
  1256.         }
  1257.       else
  1258.         break;
  1259.     }
  1260.  
  1261.       for (i = 0; i < num_tmps; i++)
  1262.     output_asm_insn (tmp_info[i].load, tmp_info[i].xops);
  1263.  
  1264.       for (i = 0; i < num_tmps; i++)
  1265.     output_asm_insn (tmp_info[i].store, tmp_info[i].xops);
  1266.     }
  1267.  
  1268.   if (length == 1)
  1269.     {
  1270.       xops[0] = adj_offsettable_operand (dest, offset);
  1271.       xops[1] = adj_offsettable_operand (src, offset);
  1272.       xops[2] = qi_tmp;
  1273.       output_asm_insn (AS2(mov%B0,%1,%2), xops);
  1274.       output_asm_insn (AS2(mov%B0,%2,%0), xops);
  1275.     }
  1276.  
  1277.   return "";
  1278. }
  1279.  
  1280.  
  1281. int
  1282. standard_80387_constant_p (x)
  1283.      rtx x;
  1284. {
  1285. #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  1286.   REAL_VALUE_TYPE d;
  1287.   jmp_buf handler;
  1288.   int is0, is1;
  1289.  
  1290.   if (setjmp (handler))
  1291.     return 0;
  1292.  
  1293.   set_float_handler (handler);
  1294.   REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1295.   is0 = REAL_VALUES_EQUAL (d, dconst0);
  1296.   is1 = REAL_VALUES_EQUAL (d, dconst1);
  1297.   set_float_handler (NULL_PTR);
  1298.  
  1299.   if (is0)
  1300.     return 1;
  1301.  
  1302.   if (is1)
  1303.     return 2;
  1304.  
  1305.   /* Note that on the 80387, other constants, such as pi,
  1306.      are much slower to load as standard constants
  1307.      than to load from doubles in memory!  */
  1308. #endif
  1309.  
  1310.   return 0;
  1311. }
  1312.  
  1313. char *
  1314. output_move_const_single (operands)
  1315.      rtx *operands;
  1316. {
  1317.   if (FP_REG_P (operands[0]))
  1318.     {
  1319.       int conval = standard_80387_constant_p (operands[1]);
  1320.  
  1321.       if (conval == 1)
  1322.     return "fldz";
  1323.  
  1324.       if (conval == 2)
  1325.     return "fld1";
  1326.     }
  1327.   if (GET_CODE (operands[1]) == CONST_DOUBLE)
  1328.     {
  1329.       REAL_VALUE_TYPE r; long l;
  1330.  
  1331.       if (GET_MODE (operands[1]) == XFmode)
  1332.     abort ();
  1333.  
  1334.       REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  1335.       REAL_VALUE_TO_TARGET_SINGLE (r, l);
  1336.       operands[1] = GEN_INT (l);
  1337.     }
  1338.   return singlemove_string (operands);
  1339. }
  1340.  
  1341. /* Returns 1 if OP is either a symbol reference or a sum of a symbol
  1342.    reference and a constant.  */
  1343.  
  1344. int
  1345. symbolic_operand (op, mode)
  1346.      register rtx op;
  1347.      enum machine_mode mode;
  1348. {
  1349.   switch (GET_CODE (op))
  1350.     {
  1351.     case SYMBOL_REF:
  1352.     case LABEL_REF:
  1353.       return 1;
  1354.     case CONST:
  1355.       op = XEXP (op, 0);
  1356.       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
  1357.            || GET_CODE (XEXP (op, 0)) == LABEL_REF)
  1358.           && GET_CODE (XEXP (op, 1)) == CONST_INT);
  1359.     default:
  1360.       return 0;
  1361.     }
  1362. }
  1363.  
  1364. /* Test for a valid operand for a call instruction.
  1365.    Don't allow the arg pointer register or virtual regs
  1366.    since they may change into reg + const, which the patterns
  1367.    can't handle yet.  */
  1368.  
  1369. int
  1370. call_insn_operand (op, mode)
  1371.      rtx op;
  1372.      enum machine_mode mode;
  1373. {
  1374.   if (GET_CODE (op) == MEM
  1375.       && ((CONSTANT_ADDRESS_P (XEXP (op, 0))
  1376.        /* This makes a difference for PIC.  */
  1377.        && general_operand (XEXP (op, 0), Pmode))
  1378.       || (GET_CODE (XEXP (op, 0)) == REG
  1379.           && XEXP (op, 0) != arg_pointer_rtx
  1380.           && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
  1381.            && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
  1382.     return 1;
  1383.   return 0;
  1384. }
  1385.  
  1386. /* Like call_insn_operand but allow (mem (symbol_ref ...))
  1387.    even if pic.  */
  1388.  
  1389. int
  1390. expander_call_insn_operand (op, mode)
  1391.      rtx op;
  1392.      enum machine_mode mode;
  1393. {
  1394.   if (GET_CODE (op) == MEM
  1395.       && (CONSTANT_ADDRESS_P (XEXP (op, 0))
  1396.       || (GET_CODE (XEXP (op, 0)) == REG
  1397.           && XEXP (op, 0) != arg_pointer_rtx
  1398.           && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER
  1399.            && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER))))
  1400.     return 1;
  1401.   return 0;
  1402. }
  1403.  
  1404. /* Returns 1 if OP contains a symbol reference */
  1405.  
  1406. int
  1407. symbolic_reference_mentioned_p (op)
  1408.      rtx op;
  1409. {
  1410.   register char *fmt;
  1411.   register int i;
  1412.  
  1413.   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
  1414.     return 1;
  1415.  
  1416.   fmt = GET_RTX_FORMAT (GET_CODE (op));
  1417.   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
  1418.     {
  1419.       if (fmt[i] == 'E')
  1420.     {
  1421.       register int j;
  1422.  
  1423.       for (j = XVECLEN (op, i) - 1; j >= 0; j--)
  1424.         if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
  1425.           return 1;
  1426.     }
  1427.       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
  1428.     return 1;
  1429.     }
  1430.  
  1431.   return 0;
  1432. }
  1433.  
  1434. /* This function generates the assembly code for function entry.
  1435.    FILE is an stdio stream to output the code to.
  1436.    SIZE is an int: how many units of temporary storage to allocate. */
  1437.  
  1438. void
  1439. function_prologue (file, size)
  1440.      FILE *file;
  1441.      int size;
  1442. {
  1443.   register int regno;
  1444.   int limit;
  1445.   rtx xops[4];
  1446.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1447.                   || current_function_uses_const_pool);
  1448.  
  1449.   xops[0] = stack_pointer_rtx;
  1450.   xops[1] = frame_pointer_rtx;
  1451.   xops[2] = GEN_INT (size);
  1452.   if (frame_pointer_needed)
  1453.     {
  1454.       output_asm_insn ("push%L1 %1", xops);
  1455.       output_asm_insn (AS2 (mov%L0,%0,%1), xops);
  1456.     }
  1457.  
  1458.   if (size)
  1459.     output_asm_insn (AS2 (sub%L0,%2,%0), xops);
  1460.  
  1461.   /* Note If use enter it is NOT reversed args.
  1462.      This one is not reversed from intel!!
  1463.      I think enter is slower.  Also sdb doesn't like it.
  1464.      But if you want it the code is:
  1465.      {
  1466.      xops[3] = const0_rtx;
  1467.      output_asm_insn ("enter %2,%3", xops);
  1468.      }
  1469.      */
  1470.   limit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
  1471.   for (regno = limit - 1; regno >= 0; regno--)
  1472.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1473.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
  1474.       {
  1475.     xops[0] = gen_rtx (REG, SImode, regno);
  1476.     output_asm_insn ("push%L0 %0", xops);
  1477.       }
  1478.  
  1479.   if (pic_reg_used)
  1480.     {
  1481.       xops[0] = pic_offset_table_rtx;
  1482.       xops[1] = (rtx) gen_label_rtx ();
  1483.  
  1484.       output_asm_insn (AS1 (call,%P1), xops);
  1485.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (xops[1]));
  1486.       output_asm_insn (AS1 (pop%L0,%0), xops);
  1487.       output_asm_insn ("addl $_GLOBAL_OFFSET_TABLE_+[.-%P1],%0", xops);
  1488.     }
  1489. }
  1490.  
  1491. /* Return 1 if it is appropriate to emit `ret' instructions in the
  1492.    body of a function.  Do this only if the epilogue is simple, needing a
  1493.    couple of insns.  Prior to reloading, we can't tell how many registers
  1494.    must be saved, so return 0 then.
  1495.  
  1496.    If NON_SAVING_SETJMP is defined and true, then it is not possible
  1497.    for the epilogue to be simple, so return 0.  This is a special case
  1498.    since NON_SAVING_SETJMP will not cause regs_ever_live to change until
  1499.    final, but jump_optimize may need to know sooner if a `return' is OK.  */
  1500.  
  1501. int
  1502. simple_386_epilogue ()
  1503. {
  1504.   int regno;
  1505.   int nregs = 0;
  1506.   int reglimit = (frame_pointer_needed
  1507.           ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
  1508.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1509.                   || current_function_uses_const_pool);
  1510.  
  1511. #ifdef NON_SAVING_SETJMP
  1512.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  1513.     return 0;
  1514. #endif
  1515.  
  1516.   if (! reload_completed)
  1517.     return 0;
  1518.  
  1519.   for (regno = reglimit - 1; regno >= 0; regno--)
  1520.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1521.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
  1522.       nregs++;
  1523.  
  1524.   return nregs == 0 || ! frame_pointer_needed;
  1525. }
  1526.  
  1527.  
  1528. /* This function generates the assembly code for function exit.
  1529.    FILE is an stdio stream to output the code to.
  1530.    SIZE is an int: how many units of temporary storage to deallocate. */
  1531.  
  1532. void
  1533. function_epilogue (file, size)
  1534.      FILE *file;
  1535.      int size;
  1536. {
  1537.   register int regno;
  1538.   register int nregs, limit;
  1539.   int offset;
  1540.   rtx xops[3];
  1541.   int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table
  1542.                   || current_function_uses_const_pool);
  1543.  
  1544.   /* Compute the number of registers to pop */
  1545.  
  1546.   limit = (frame_pointer_needed
  1547.        ? FRAME_POINTER_REGNUM
  1548.        : STACK_POINTER_REGNUM);
  1549.  
  1550.   nregs = 0;
  1551.  
  1552.   for (regno = limit - 1; regno >= 0; regno--)
  1553.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1554.     || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
  1555.       nregs++;
  1556.  
  1557.   /* sp is often  unreliable so we must go off the frame pointer,
  1558.    */
  1559.  
  1560.   /* In reality, we may not care if sp is unreliable, because we can
  1561.      restore the register relative to the frame pointer.  In theory,
  1562.      since each move is the same speed as a pop, and we don't need the
  1563.      leal, this is faster.  For now restore multiple registers the old
  1564.      way. */
  1565.  
  1566.   offset = -size - (nregs * UNITS_PER_WORD);
  1567.  
  1568.   xops[2] = stack_pointer_rtx;
  1569.  
  1570.   if (nregs > 1 || ! frame_pointer_needed)
  1571.     {
  1572.       if (frame_pointer_needed)
  1573.     {
  1574.       xops[0] = adj_offsettable_operand (AT_BP (Pmode), offset);
  1575.       output_asm_insn (AS2 (lea%L2,%0,%2), xops);
  1576.     }
  1577.  
  1578.       for (regno = 0; regno < limit; regno++)
  1579.     if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1580.         || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
  1581.       {
  1582.         xops[0] = gen_rtx (REG, SImode, regno);
  1583.         output_asm_insn ("pop%L0 %0", xops);
  1584.       }
  1585.     }
  1586.   else
  1587.     for (regno = 0; regno < limit; regno++)
  1588.       if ((regs_ever_live[regno] && ! call_used_regs[regno])
  1589.       || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
  1590.     {
  1591.       xops[0] = gen_rtx (REG, SImode, regno);
  1592.       xops[1] = adj_offsettable_operand (AT_BP (Pmode), offset);
  1593.       output_asm_insn (AS2 (mov%L0,%1,%0), xops);
  1594.       offset += 4;
  1595.     }
  1596.  
  1597.   if (frame_pointer_needed)
  1598.     {
  1599.       /* On i486, mov & pop is faster than "leave". */
  1600.  
  1601.       if (!TARGET_386)
  1602.     {
  1603.       xops[0] = frame_pointer_rtx;
  1604.       output_asm_insn (AS2 (mov%L2,%0,%2), xops);
  1605.       output_asm_insn ("pop%L0 %0", xops);
  1606.     }
  1607.       else
  1608.     output_asm_insn ("leave", xops);
  1609.     }
  1610.   else if (size)
  1611.     {
  1612.       /* If there is no frame pointer, we must still release the frame. */
  1613.  
  1614.       xops[0] = GEN_INT (size);
  1615.       output_asm_insn (AS2 (add%L2,%0,%2), xops);
  1616.     }
  1617.  
  1618.   if (current_function_pops_args && current_function_args_size)
  1619.     {
  1620.       xops[1] = GEN_INT (current_function_pops_args);
  1621.  
  1622.       /* i386 can only pop 32K bytes (maybe 64K?  Is it signed?).  If
  1623.      asked to pop more, pop return address, do explicit add, and jump
  1624.      indirectly to the caller. */
  1625.  
  1626.       if (current_function_pops_args >= 32768)
  1627.     {
  1628.       /* ??? Which register to use here? */
  1629.       xops[0] = gen_rtx (REG, SImode, 2);
  1630.       output_asm_insn ("pop%L0 %0", xops);
  1631.       output_asm_insn (AS2 (add%L2,%1,%2), xops);
  1632.       output_asm_insn ("jmp %*%0", xops);
  1633.     }
  1634.       else
  1635.       output_asm_insn ("ret %1", xops);
  1636.     }
  1637.   else
  1638.     output_asm_insn ("ret", xops);
  1639. }
  1640.  
  1641.  
  1642. /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
  1643.    that is a valid memory address for an instruction.
  1644.    The MODE argument is the machine mode for the MEM expression
  1645.    that wants to use this address.
  1646.  
  1647.    On x86, legitimate addresses are:
  1648.     base                movl (base),reg
  1649.     displacement            movl disp,reg
  1650.     base + displacement        movl disp(base),reg
  1651.     index + base            movl (base,index),reg
  1652.     (index + base) + displacement    movl disp(base,index),reg
  1653.     index*scale            movl (,index,scale),reg
  1654.     index*scale + disp        movl disp(,index,scale),reg
  1655.     index*scale + base         movl (base,index,scale),reg
  1656.     (index*scale + base) + disp    movl disp(base,index,scale),reg
  1657.  
  1658.     In each case, scale can be 1, 2, 4, 8.  */
  1659.  
  1660. /* This is exactly the same as print_operand_addr, except that
  1661.    it recognizes addresses instead of printing them.
  1662.  
  1663.    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
  1664.    convert common non-canonical forms to canonical form so that they will
  1665.    be recognized.  */
  1666.  
  1667. #define ADDR_INVALID(msg,insn)                        \
  1668. do {                                    \
  1669.   if (TARGET_DEBUG_ADDR)                        \
  1670.     {                                    \
  1671.       fprintf (stderr, msg);                        \
  1672.       debug_rtx (insn);                            \
  1673.     }                                    \
  1674. } while (0)
  1675.  
  1676. int
  1677. legitimate_address_p (mode, addr, strict)
  1678.      enum machine_mode mode;
  1679.      register rtx addr;
  1680.      int strict;
  1681. {
  1682.   rtx base  = NULL_RTX;
  1683.   rtx indx  = NULL_RTX;
  1684.   rtx scale = NULL_RTX;
  1685.   rtx disp  = NULL_RTX;
  1686.  
  1687.   if (TARGET_DEBUG_ADDR)
  1688.     {
  1689.       fprintf (stderr,
  1690.            "\n==========\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n",
  1691.            GET_MODE_NAME (mode), strict);
  1692.  
  1693.       debug_rtx (addr);
  1694.     }
  1695.  
  1696.   if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG)
  1697.       base = addr;                /* base reg */
  1698.  
  1699.   else if (GET_CODE (addr) == PLUS)
  1700.     {
  1701.       rtx op0 = XEXP (addr, 0);
  1702.       rtx op1 = XEXP (addr, 1);
  1703.       enum rtx_code code0 = GET_CODE (op0);
  1704.       enum rtx_code code1 = GET_CODE (op1);
  1705.  
  1706.       if (code0 == REG || code0 == SUBREG)
  1707.     {
  1708.       if (code1 == REG || code1 == SUBREG)
  1709.         {
  1710.           indx = op0;            /* index + base */
  1711.           base = op1;
  1712.         }
  1713.  
  1714.       else
  1715.         {
  1716.           base = op0;            /* base + displacement */
  1717.           disp = op1;
  1718.         }
  1719.     }
  1720.  
  1721.       else if (code0 == MULT)
  1722.     {
  1723.       indx  = XEXP (op0, 0);
  1724.       scale = XEXP (op0, 1);
  1725.  
  1726.       if (code1 == REG || code1 == SUBREG)
  1727.         base = op1;                /* index*scale + base */
  1728.  
  1729.       else
  1730.         disp = op1;                /* index*scale + disp */
  1731.     }
  1732.  
  1733.       else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT)
  1734.     {
  1735.       indx  = XEXP (XEXP (op0, 0), 0);    /* index*scale + base + disp */
  1736.       scale = XEXP (XEXP (op0, 0), 1);
  1737.       base  = XEXP (op0, 1);
  1738.       disp  = op1;
  1739.     }
  1740.  
  1741.       else if (code0 == PLUS)
  1742.     {
  1743.       indx = XEXP (op0, 0);            /* index + base + disp */
  1744.       base = XEXP (op0, 1);
  1745.       disp = op1;
  1746.     }
  1747.  
  1748.       else
  1749.     {
  1750.       ADDR_INVALID ("PLUS subcode is not valid.\n", op0);
  1751.       return FALSE;
  1752.     }
  1753.     }
  1754.  
  1755.   else if (GET_CODE (addr) == MULT)
  1756.     {
  1757.       indx  = XEXP (addr, 0);            /* index*scale */
  1758.       scale = XEXP (addr, 1);
  1759.     }
  1760.  
  1761.   else
  1762.     disp = addr;                /* displacement */
  1763.  
  1764.   /* Allow arg pointer and stack pointer as index if there is not scaling */
  1765.   if (base && indx && !scale
  1766.       && (indx == arg_pointer_rtx || indx == stack_pointer_rtx))
  1767.     {
  1768.       rtx tmp = base;
  1769.       base = indx;
  1770.       indx = tmp;
  1771.     }
  1772.  
  1773.   /* Validate base register */
  1774.   /* Don't allow SUBREG's here, it can lead to spill failures when the base
  1775.      is one word out of a two word structure, which is represented internally
  1776.      as a DImode int.  */
  1777.   if (base)
  1778.     {
  1779.       if (GET_CODE (base) != REG)
  1780.     {
  1781.       ADDR_INVALID ("Base is not a register.\n", base);
  1782.       return FALSE;
  1783.     }
  1784.  
  1785.       if ((strict && !REG_OK_FOR_BASE_STRICT_P (base))
  1786.       || (!strict && !REG_OK_FOR_BASE_NONSTRICT_P (base)))
  1787.     {
  1788.       ADDR_INVALID ("Base is not valid.\n", base);
  1789.       return FALSE;
  1790.     }
  1791.     }
  1792.  
  1793.   /* Validate index register */
  1794.   /* Don't allow SUBREG's here, it can lead to spill failures when the index
  1795.      is one word out of a two word structure, which is represented internally
  1796.      as a DImode int.  */
  1797.   if (indx)
  1798.     {
  1799.       if (GET_CODE (indx) != REG)
  1800.     {
  1801.       ADDR_INVALID ("Index is not a register.\n", indx);
  1802.       return FALSE;
  1803.     }
  1804.  
  1805.       if ((strict && !REG_OK_FOR_INDEX_STRICT_P (indx))
  1806.       || (!strict && !REG_OK_FOR_INDEX_NONSTRICT_P (indx)))
  1807.     {
  1808.       ADDR_INVALID ("Index is not valid.\n", indx);
  1809.       return FALSE;
  1810.     }
  1811.     }
  1812.   else if (scale)
  1813.     abort ();                    /* scale w/o index invalid */
  1814.  
  1815.   /* Validate scale factor */
  1816.   if (scale)
  1817.     {
  1818.       HOST_WIDE_INT value;
  1819.  
  1820.       if (GET_CODE (scale) != CONST_INT)
  1821.     {
  1822.       ADDR_INVALID ("Scale is not valid.\n", scale);
  1823.       return FALSE;
  1824.     }
  1825.  
  1826.       value = INTVAL (scale);
  1827.       if (value != 1 && value != 2 && value != 4 && value != 8)
  1828.     {
  1829.       ADDR_INVALID ("Scale is not a good multiplier.\n", scale);
  1830.       return FALSE;
  1831.     }
  1832.     }
  1833.  
  1834.   /* Validate displacement */
  1835.   if (disp)
  1836.     {
  1837.       if (!CONSTANT_ADDRESS_P (disp))
  1838.     {
  1839.       ADDR_INVALID ("Displacement is not valid.\n", disp);
  1840.       return FALSE;
  1841.     }
  1842.  
  1843.       if (GET_CODE (disp) == CONST_DOUBLE)
  1844.     {
  1845.       ADDR_INVALID ("Displacement is a const_double.\n", disp);
  1846.       return FALSE;
  1847.     }
  1848.  
  1849.       if (flag_pic && SYMBOLIC_CONST (disp) && base != pic_offset_table_rtx
  1850.       && (indx != pic_offset_table_rtx || scale != NULL_RTX))
  1851.     {
  1852.       ADDR_INVALID ("Displacement is an invalid pic reference.\n", disp);
  1853.       return FALSE;
  1854.     }
  1855.  
  1856.       if (HALF_PIC_P () && HALF_PIC_ADDRESS_P (disp)
  1857.       && (base != NULL_RTX || indx != NULL_RTX))
  1858.     {
  1859.       ADDR_INVALID ("Displacement is an invalid half-pic reference.\n", disp);
  1860.       return FALSE;
  1861.     }
  1862.     }
  1863.  
  1864.   if (TARGET_DEBUG_ADDR)
  1865.     fprintf (stderr, "Address is valid.\n");
  1866.  
  1867.   /* Everything looks valid, return true */
  1868.   return TRUE;
  1869. }
  1870.  
  1871.  
  1872. /* Return a legitimate reference for ORIG (an address) using the
  1873.    register REG.  If REG is 0, a new pseudo is generated.
  1874.  
  1875.    There are three types of references that must be handled:
  1876.  
  1877.    1. Global data references must load the address from the GOT, via
  1878.       the PIC reg.  An insn is emitted to do this load, and the reg is
  1879.       returned.
  1880.  
  1881.    2. Static data references must compute the address as an offset
  1882.       from the GOT, whose base is in the PIC reg.  An insn is emitted to
  1883.       compute the address into a reg, and the reg is returned.  Static
  1884.       data objects have SYMBOL_REF_FLAG set to differentiate them from
  1885.       global data objects.
  1886.  
  1887.    3. Constant pool addresses must be handled special.  They are
  1888.       considered legitimate addresses, but only if not used with regs.
  1889.       When printed, the output routines know to print the reference with the
  1890.       PIC reg, even though the PIC reg doesn't appear in the RTL.
  1891.  
  1892.    GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
  1893.    reg also appears in the address (except for constant pool references,
  1894.    noted above).
  1895.  
  1896.    "switch" statements also require special handling when generating
  1897.    PIC code.  See comments by the `casesi' insn in i386.md for details.  */
  1898.  
  1899. rtx
  1900. legitimize_pic_address (orig, reg)
  1901.      rtx orig;
  1902.      rtx reg;
  1903. {
  1904.   rtx addr = orig;
  1905.   rtx new = orig;
  1906.  
  1907.   if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF)
  1908.     {
  1909.       if (GET_CODE (addr) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (addr))
  1910.     reg = new = orig;
  1911.       else
  1912.     {
  1913.       if (reg == 0)
  1914.         reg = gen_reg_rtx (Pmode);
  1915.  
  1916.       if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_FLAG (addr))
  1917.           || GET_CODE (addr) == LABEL_REF)
  1918.         new = gen_rtx (PLUS, Pmode, pic_offset_table_rtx, orig);
  1919.       else
  1920.         new = gen_rtx (MEM, Pmode,
  1921.                gen_rtx (PLUS, Pmode,
  1922.                     pic_offset_table_rtx, orig));
  1923.  
  1924.       emit_move_insn (reg, new);
  1925.     }
  1926.       current_function_uses_pic_offset_table = 1;
  1927.       return reg;
  1928.     }
  1929.   else if (GET_CODE (addr) == CONST || GET_CODE (addr) == PLUS)
  1930.     {
  1931.       rtx base;
  1932.  
  1933.       if (GET_CODE (addr) == CONST)
  1934.     {
  1935.       addr = XEXP (addr, 0);
  1936.       if (GET_CODE (addr) != PLUS)
  1937.         abort ();
  1938.     }
  1939.  
  1940.       if (XEXP (addr, 0) == pic_offset_table_rtx)
  1941.     return orig;
  1942.  
  1943.       if (reg == 0)
  1944.     reg = gen_reg_rtx (Pmode);
  1945.  
  1946.       base = legitimize_pic_address (XEXP (addr, 0), reg);
  1947.       addr = legitimize_pic_address (XEXP (addr, 1),
  1948.                      base == reg ? NULL_RTX : reg);
  1949.  
  1950.       if (GET_CODE (addr) == CONST_INT)
  1951.     return plus_constant (base, INTVAL (addr));
  1952.  
  1953.       if (GET_CODE (addr) == PLUS && CONSTANT_P (XEXP (addr, 1)))
  1954.     {
  1955.       base = gen_rtx (PLUS, Pmode, base, XEXP (addr, 0));
  1956.       addr = XEXP (addr, 1);
  1957.     }
  1958.     return gen_rtx (PLUS, Pmode, base, addr);
  1959.     }
  1960.   return new;
  1961. }
  1962.  
  1963.  
  1964. /* Emit insns to move operands[1] into operands[0].  */
  1965.  
  1966. void
  1967. emit_pic_move (operands, mode)
  1968.      rtx *operands;
  1969.      enum machine_mode mode;
  1970. {
  1971.   rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode);
  1972.  
  1973.   if (GET_CODE (operands[0]) == MEM && SYMBOLIC_CONST (operands[1]))
  1974.     operands[1] = (rtx) force_reg (SImode, operands[1]);
  1975.   else
  1976.     operands[1] = legitimize_pic_address (operands[1], temp);
  1977. }
  1978.  
  1979.  
  1980. /* Try machine-dependent ways of modifying an illegitimate address
  1981.    to be legitimate.  If we find one, return the new, valid address.
  1982.    This macro is used in only one place: `memory_address' in explow.c.
  1983.  
  1984.    OLDX is the address as it was before break_out_memory_refs was called.
  1985.    In some cases it is useful to look at this to decide what needs to be done.
  1986.  
  1987.    MODE and WIN are passed so that this macro can use
  1988.    GO_IF_LEGITIMATE_ADDRESS.
  1989.  
  1990.    It is always safe for this macro to do nothing.  It exists to recognize
  1991.    opportunities to optimize the output.
  1992.  
  1993.    For the 80386, we handle X+REG by loading X into a register R and
  1994.    using R+REG.  R will go in a general reg and indexing will be used.
  1995.    However, if REG is a broken-out memory address or multiplication,
  1996.    nothing needs to be done because REG can certainly go in a general reg.
  1997.  
  1998.    When -fpic is used, special handling is needed for symbolic references.
  1999.    See comments by legitimize_pic_address in i386.c for details.  */
  2000.  
  2001. rtx
  2002. legitimize_address (x, oldx, mode)
  2003.      register rtx x;
  2004.      register rtx oldx;
  2005.      enum machine_mode mode;
  2006. {
  2007.   int changed = 0;
  2008.   unsigned log;
  2009.  
  2010.   if (TARGET_DEBUG_ADDR)
  2011.     {
  2012.       fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n", GET_MODE_NAME (mode));
  2013.       debug_rtx (x);
  2014.     }
  2015.  
  2016.   if (flag_pic && SYMBOLIC_CONST (x))
  2017.     return legitimize_pic_address (x, 0);
  2018.  
  2019.   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
  2020.   if (GET_CODE (x) == ASHIFT
  2021.       && GET_CODE (XEXP (x, 1)) == CONST_INT
  2022.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4)
  2023.     {
  2024.       changed = 1;
  2025.       x = gen_rtx (MULT, Pmode,
  2026.            force_reg (Pmode, XEXP (x, 0)),
  2027.            GEN_INT (1 << log));
  2028.     }
  2029.  
  2030.   if (GET_CODE (x) == PLUS)
  2031.     {
  2032.       /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
  2033.       if (GET_CODE (XEXP (x, 0)) == ASHIFT
  2034.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  2035.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4)
  2036.     {
  2037.       changed = 1;
  2038.       XEXP (x, 0) = gen_rtx (MULT, Pmode,
  2039.                  force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
  2040.                  GEN_INT (1 << log));
  2041.     }
  2042.  
  2043.       if (GET_CODE (XEXP (x, 1)) == ASHIFT
  2044.       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
  2045.       && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4)
  2046.     {
  2047.       changed = 1;
  2048.       XEXP (x, 1) = gen_rtx (MULT, Pmode,
  2049.                  force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
  2050.                  GEN_INT (1 << log));
  2051.     }
  2052.  
  2053.       /* Put multiply first if it isn't already */
  2054.       if (GET_CODE (XEXP (x, 1)) == MULT)
  2055.     {
  2056.       rtx tmp = XEXP (x, 0);
  2057.       XEXP (x, 0) = XEXP (x, 1);
  2058.       XEXP (x, 1) = tmp;
  2059.       changed = 1;
  2060.     }
  2061.  
  2062.       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
  2063.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
  2064.      created by virtual register instantiation, register elimination, and
  2065.      similar optimizations.  */
  2066.       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
  2067.     {
  2068.       changed = 1;
  2069.       x = gen_rtx (PLUS, Pmode,
  2070.                gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
  2071.                XEXP (XEXP (x, 1), 1));
  2072.     }
  2073.  
  2074.       /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
  2075.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
  2076.       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
  2077.            && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
  2078.            && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
  2079.            && CONSTANT_P (XEXP (x, 1)))
  2080.     {
  2081.       rtx constant, other;
  2082.  
  2083.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  2084.         {
  2085.           constant = XEXP (x, 1);
  2086.           other = XEXP (XEXP (XEXP (x, 0), 1), 1);
  2087.         }
  2088.       else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
  2089.         {
  2090.           constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
  2091.           other = XEXP (x, 1);
  2092.         }
  2093.       else
  2094.         constant = 0;
  2095.  
  2096.       if (constant)
  2097.         {
  2098.           changed = 1;
  2099.           x = gen_rtx (PLUS, Pmode,
  2100.                gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
  2101.                     XEXP (XEXP (XEXP (x, 0), 1), 0)),
  2102.                plus_constant (other, INTVAL (constant)));
  2103.         }
  2104.     }
  2105.  
  2106.       if (changed && legitimate_address_p (mode, x, FALSE))
  2107.     return x;
  2108.  
  2109.       if (GET_CODE (XEXP (x, 0)) == MULT)
  2110.     {
  2111.       changed = 1;
  2112.       XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
  2113.     }
  2114.  
  2115.       if (GET_CODE (XEXP (x, 1)) == MULT)
  2116.     {
  2117.       changed = 1;
  2118.       XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
  2119.     }
  2120.  
  2121.       if (changed
  2122.       && GET_CODE (XEXP (x, 1)) == REG
  2123.       && GET_CODE (XEXP (x, 0)) == REG)
  2124.     return x;
  2125.  
  2126.       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
  2127.     {
  2128.       changed = 1;
  2129.       x = legitimize_pic_address (x, 0);
  2130.     }
  2131.  
  2132.       if (changed && legitimate_address_p (mode, x, FALSE))
  2133.     return x;
  2134.  
  2135.       if (GET_CODE (XEXP (x, 0)) == REG)
  2136.     {
  2137.       register rtx temp = gen_reg_rtx (Pmode);
  2138.       register rtx val  = force_operand (XEXP (x, 1), temp);
  2139.       if (val != temp)
  2140.         emit_move_insn (temp, val);
  2141.  
  2142.       XEXP (x, 1) = temp;
  2143.       return x;
  2144.     }
  2145.  
  2146.       else if (GET_CODE (XEXP (x, 1)) == REG)
  2147.     {
  2148.       register rtx temp = gen_reg_rtx (Pmode);
  2149.       register rtx val  = force_operand (XEXP (x, 0), temp);
  2150.       if (val != temp)
  2151.         emit_move_insn (temp, val);
  2152.  
  2153.       XEXP (x, 0) = temp;
  2154.       return x;
  2155.     }
  2156.     }
  2157.  
  2158.   return x;
  2159. }
  2160.  
  2161.  
  2162. /* Print an integer constant expression in assembler syntax.  Addition
  2163.    and subtraction are the only arithmetic that may appear in these
  2164.    expressions.  FILE is the stdio stream to write to, X is the rtx, and
  2165.    CODE is the operand print code from the output string.  */
  2166.  
  2167. static void
  2168. output_pic_addr_const (file, x, code)
  2169.      FILE *file;
  2170.      rtx x;
  2171.      int code;
  2172. {
  2173.   char buf[256];
  2174.  
  2175.   switch (GET_CODE (x))
  2176.     {
  2177.     case PC:
  2178.       if (flag_pic)
  2179.     putc ('.', file);
  2180.       else
  2181.     abort ();
  2182.       break;
  2183.  
  2184.     case SYMBOL_REF:
  2185.     case LABEL_REF:
  2186.       if (GET_CODE (x) == SYMBOL_REF)
  2187.     assemble_name (file, XSTR (x, 0));
  2188.       else
  2189.     {
  2190.       ASM_GENERATE_INTERNAL_LABEL (buf, "L",
  2191.                        CODE_LABEL_NUMBER (XEXP (x, 0)));
  2192.       assemble_name (asm_out_file, buf);
  2193.     }
  2194.  
  2195.       if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
  2196.     fprintf (file, "@GOTOFF(%%ebx)");
  2197.       else if (code == 'P')
  2198.     fprintf (file, "@PLT");
  2199.       else if (GET_CODE (x) == LABEL_REF)
  2200.     fprintf (file, "@GOTOFF");
  2201.       else if (! SYMBOL_REF_FLAG (x))
  2202.     fprintf (file, "@GOT");
  2203.       else
  2204.     fprintf (file, "@GOTOFF");
  2205.  
  2206.       break;
  2207.  
  2208.     case CODE_LABEL:
  2209.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  2210.       assemble_name (asm_out_file, buf);
  2211.       break;
  2212.  
  2213.     case CONST_INT:
  2214.       fprintf (file, "%d", INTVAL (x));
  2215.       break;
  2216.  
  2217.     case CONST:
  2218.       /* This used to output parentheses around the expression,
  2219.      but that does not work on the 386 (either ATT or BSD assembler).  */
  2220.       output_pic_addr_const (file, XEXP (x, 0), code);
  2221.       break;
  2222.  
  2223.     case CONST_DOUBLE:
  2224.       if (GET_MODE (x) == VOIDmode)
  2225.     {
  2226.       /* We can use %d if the number is <32 bits and positive.  */
  2227.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  2228.         fprintf (file, "0x%x%08x",
  2229.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  2230.       else
  2231.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  2232.     }
  2233.       else
  2234.     /* We can't handle floating point constants;
  2235.        PRINT_OPERAND must handle them.  */
  2236.     output_operand_lossage ("floating constant misused");
  2237.       break;
  2238.  
  2239.     case PLUS:
  2240.       /* Some assemblers need integer constants to appear last (eg masm).  */
  2241.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  2242.     {
  2243.       output_pic_addr_const (file, XEXP (x, 1), code);
  2244.       if (INTVAL (XEXP (x, 0)) >= 0)
  2245.         fprintf (file, "+");
  2246.       output_pic_addr_const (file, XEXP (x, 0), code);
  2247.     }
  2248.       else
  2249.     {
  2250.       output_pic_addr_const (file, XEXP (x, 0), code);
  2251.       if (INTVAL (XEXP (x, 1)) >= 0)
  2252.         fprintf (file, "+");
  2253.       output_pic_addr_const (file, XEXP (x, 1), code);
  2254.     }
  2255.       break;
  2256.  
  2257.     case MINUS:
  2258.       output_pic_addr_const (file, XEXP (x, 0), code);
  2259.       fprintf (file, "-");
  2260.       output_pic_addr_const (file, XEXP (x, 1), code);
  2261.       break;
  2262.  
  2263.     default:
  2264.       output_operand_lossage ("invalid expression as operand");
  2265.     }
  2266. }
  2267.  
  2268. /* Meaning of CODE:
  2269.    f -- float insn (print a CONST_DOUBLE as a float rather than in hex).
  2270.    D,L,W,B,Q,S -- print the opcode suffix for specified size of operand.
  2271.    R -- print the prefix for register names.
  2272.    z -- print the opcode suffix for the size of the current operand.
  2273.    * -- print a star (in certain assembler syntax)
  2274.    w -- print the operand as if it's a "word" (HImode) even if it isn't.
  2275.    c -- don't print special prefixes before constant operands.
  2276.    J -- print the appropriate jump operand.
  2277. */
  2278.  
  2279. void
  2280. print_operand (file, x, code)
  2281.      FILE *file;
  2282.      rtx x;
  2283.      int code;
  2284. {
  2285.   if (code)
  2286.     {
  2287.       switch (code)
  2288.     {
  2289.     case '*':
  2290.       if (USE_STAR)
  2291.         putc ('*', file);
  2292.       return;
  2293.  
  2294.     case 'L':
  2295.       PUT_OP_SIZE (code, 'l', file);
  2296.       return;
  2297.  
  2298.     case 'W':
  2299.       PUT_OP_SIZE (code, 'w', file);
  2300.       return;
  2301.  
  2302.     case 'B':
  2303.       PUT_OP_SIZE (code, 'b', file);
  2304.       return;
  2305.  
  2306.     case 'Q':
  2307.       PUT_OP_SIZE (code, 'l', file);
  2308.       return;
  2309.  
  2310.     case 'S':
  2311.       PUT_OP_SIZE (code, 's', file);
  2312.       return;
  2313.  
  2314.     case 'T':
  2315.       PUT_OP_SIZE (code, 't', file);
  2316.       return;
  2317.  
  2318.     case 'z':
  2319.       /* 387 opcodes don't get size suffixes if the operands are
  2320.          registers. */
  2321.  
  2322.       if (STACK_REG_P (x))
  2323.         return;
  2324.  
  2325.       /* this is the size of op from size of operand */
  2326.       switch (GET_MODE_SIZE (GET_MODE (x)))
  2327.         {
  2328.         case 1:
  2329.           PUT_OP_SIZE ('B', 'b', file);
  2330.           return;
  2331.  
  2332.         case 2:
  2333.           PUT_OP_SIZE ('W', 'w', file);
  2334.           return;
  2335.  
  2336.         case 4:
  2337.           if (GET_MODE (x) == SFmode)
  2338.         {
  2339.           PUT_OP_SIZE ('S', 's', file);
  2340.           return;
  2341.         }
  2342.           else
  2343.         PUT_OP_SIZE ('L', 'l', file);
  2344.           return;
  2345.  
  2346.         case 12:
  2347.           PUT_OP_SIZE ('T', 't', file);
  2348.           return;
  2349.  
  2350.         case 8:
  2351.           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
  2352.         {
  2353. #ifdef GAS_MNEMONICS
  2354.           PUT_OP_SIZE ('Q', 'q', file);
  2355.           return;
  2356. #else
  2357.           PUT_OP_SIZE ('Q', 'l', file);    /* Fall through */
  2358. #endif
  2359.         }
  2360.  
  2361.           PUT_OP_SIZE ('Q', 'l', file);
  2362.           return;
  2363.         }
  2364.  
  2365.     case 'b':
  2366.     case 'w':
  2367.     case 'k':
  2368.     case 'h':
  2369.     case 'y':
  2370.     case 'P':
  2371.       break;
  2372.  
  2373.     case 'J':
  2374.       switch (GET_CODE (x))
  2375.         {
  2376.         case NE:  fputs ("jne", file); return;
  2377.         case EQ:  fputs ("je",  file); return;
  2378.         case GE:  fputs ("jge", file); return;
  2379.         case GT:  fputs ("jg",  file); return;
  2380.         case LE:  fputs ("jle", file); return;
  2381.         case LT:  fputs ("jl",  file); return;
  2382.         case GEU: fputs ("jae", file); return;
  2383.         case GTU: fputs ("ja",  file); return;
  2384.         case LEU: fputs ("jbe", file); return;
  2385.         case LTU: fputs ("jb",  file); return;
  2386.         }
  2387.       abort ();
  2388.  
  2389.     default:
  2390.       {
  2391.         char str[50];
  2392.  
  2393.         sprintf (str, "invalid operand code `%c'", code);
  2394.         output_operand_lossage (str);
  2395.       }
  2396.     }
  2397.     }
  2398.   if (GET_CODE (x) == REG)
  2399.     {
  2400.       PRINT_REG (x, code, file);
  2401.     }
  2402.   else if (GET_CODE (x) == MEM)
  2403.     {
  2404.       PRINT_PTR (x, file);
  2405.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  2406.     {
  2407.       if (flag_pic)
  2408.         output_pic_addr_const (file, XEXP (x, 0), code);
  2409.       else
  2410.         output_addr_const (file, XEXP (x, 0));
  2411.     }
  2412.       else
  2413.     output_address (XEXP (x, 0));
  2414.     }
  2415.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
  2416.     {
  2417.       REAL_VALUE_TYPE r; long l;
  2418.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2419.       REAL_VALUE_TO_TARGET_SINGLE (r, l);
  2420.       PRINT_IMMED_PREFIX (file);
  2421.       fprintf (file, "0x%x", l);
  2422.     }
  2423.  /* These float cases don't actually occur as immediate operands. */
  2424.  else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
  2425.     {
  2426.       REAL_VALUE_TYPE r; char dstr[30];
  2427.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2428.       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
  2429.       fprintf (file, "%s", dstr);
  2430.     }
  2431.   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
  2432.     {
  2433.       REAL_VALUE_TYPE r; char dstr[30];
  2434.       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  2435.       REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr);
  2436.       fprintf (file, "%s", dstr);
  2437.     }
  2438.   else 
  2439.     {
  2440.       if (code != 'P')
  2441.     {
  2442.       if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
  2443.         PRINT_IMMED_PREFIX (file);
  2444.       else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
  2445.            || GET_CODE (x) == LABEL_REF)
  2446.         PRINT_OFFSET_PREFIX (file);
  2447.     }
  2448.       if (flag_pic)
  2449.     output_pic_addr_const (file, x, code);
  2450.       else
  2451.     output_addr_const (file, x);
  2452.     }
  2453. }
  2454.  
  2455. /* Print a memory operand whose address is ADDR.  */
  2456.  
  2457. void
  2458. print_operand_address (file, addr)
  2459.      FILE *file;
  2460.      register rtx addr;
  2461. {
  2462.   register rtx reg1, reg2, breg, ireg;
  2463.   rtx offset;
  2464.  
  2465.   switch (GET_CODE (addr))
  2466.     {
  2467.     case REG:
  2468.       ADDR_BEG (file);
  2469.       fprintf (file, "%se", RP);
  2470.       fputs (hi_reg_name[REGNO (addr)], file);
  2471.       ADDR_END (file);
  2472.       break;
  2473.  
  2474.     case PLUS:
  2475.       reg1 = 0;
  2476.       reg2 = 0;
  2477.       ireg = 0;
  2478.       breg = 0;
  2479.       offset = 0;
  2480.       if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
  2481.     {
  2482.       offset = XEXP (addr, 0);
  2483.       addr = XEXP (addr, 1);
  2484.     }
  2485.       else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
  2486.     {
  2487.       offset = XEXP (addr, 1);
  2488.       addr = XEXP (addr, 0);
  2489.     }
  2490.       if (GET_CODE (addr) != PLUS) ;
  2491.       else if (GET_CODE (XEXP (addr, 0)) == MULT)
  2492.     {
  2493.       reg1 = XEXP (addr, 0);
  2494.       addr = XEXP (addr, 1);
  2495.     }
  2496.       else if (GET_CODE (XEXP (addr, 1)) == MULT)
  2497.     {
  2498.       reg1 = XEXP (addr, 1);
  2499.       addr = XEXP (addr, 0);
  2500.     }
  2501.       else if (GET_CODE (XEXP (addr, 0)) == REG)
  2502.     {
  2503.       reg1 = XEXP (addr, 0);
  2504.       addr = XEXP (addr, 1);
  2505.     }
  2506.       else if (GET_CODE (XEXP (addr, 1)) == REG)
  2507.     {
  2508.       reg1 = XEXP (addr, 1);
  2509.       addr = XEXP (addr, 0);
  2510.     }
  2511.       if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT)
  2512.     {
  2513.       if (reg1 == 0) reg1 = addr;
  2514.       else reg2 = addr;
  2515.       addr = 0;
  2516.     }
  2517.       if (offset != 0)
  2518.     {
  2519.       if (addr != 0) abort ();
  2520.       addr = offset;
  2521.     }
  2522.       if ((reg1 && GET_CODE (reg1) == MULT)
  2523.       || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2))))
  2524.     {
  2525.       breg = reg2;
  2526.       ireg = reg1;
  2527.     }
  2528.       else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1)))
  2529.     {
  2530.       breg = reg1;
  2531.       ireg = reg2;
  2532.     }
  2533.  
  2534.       if (ireg != 0 || breg != 0)
  2535.     {
  2536.       int scale = 1;
  2537.  
  2538.       if (addr != 0)
  2539.         {
  2540.           if (flag_pic)
  2541.         output_pic_addr_const (file, addr, 0);
  2542.  
  2543.           else if (GET_CODE (addr) == LABEL_REF)
  2544.         output_asm_label (addr);
  2545.  
  2546.           else
  2547.         output_addr_const (file, addr);
  2548.         }
  2549.  
  2550.         if (ireg != 0 && GET_CODE (ireg) == MULT)
  2551.         {
  2552.           scale = INTVAL (XEXP (ireg, 1));
  2553.           ireg = XEXP (ireg, 0);
  2554.         }
  2555.  
  2556.       /* The stack pointer can only appear as a base register,
  2557.          never an index register, so exchange the regs if it is wrong. */
  2558.  
  2559.       if (scale == 1 && ireg && REGNO (ireg) == STACK_POINTER_REGNUM)
  2560.         {
  2561.           rtx tmp;
  2562.  
  2563.           tmp = breg;
  2564.           breg = ireg;
  2565.           ireg = tmp;
  2566.         }
  2567.  
  2568.       /* output breg+ireg*scale */
  2569.       PRINT_B_I_S (breg, ireg, scale, file);
  2570.       break;
  2571.     }
  2572.  
  2573.     case MULT:
  2574.       {
  2575.     int scale;
  2576.     if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
  2577.       {
  2578.         scale = INTVAL (XEXP (addr, 0));
  2579.         ireg = XEXP (addr, 1);
  2580.       }
  2581.     else
  2582.       {
  2583.         scale = INTVAL (XEXP (addr, 1));
  2584.         ireg = XEXP (addr, 0);
  2585.       }
  2586.     output_addr_const (file, const0_rtx);
  2587.     PRINT_B_I_S ((rtx) 0, ireg, scale, file);
  2588.       }
  2589.       break;
  2590.  
  2591.     default:
  2592.       if (GET_CODE (addr) == CONST_INT
  2593.       && INTVAL (addr) < 0x8000
  2594.       && INTVAL (addr) >= -0x8000)
  2595.     fprintf (file, "%d", INTVAL (addr));
  2596.       else
  2597.     {
  2598.       if (flag_pic)
  2599.         output_pic_addr_const (file, addr, 0);
  2600.       else
  2601.         output_addr_const (file, addr);
  2602.     }
  2603.     }
  2604. }
  2605.  
  2606. /* Set the cc_status for the results of an insn whose pattern is EXP.
  2607.    On the 80386, we assume that only test and compare insns, as well
  2608.    as SI, HI, & DI mode ADD, SUB, NEG, AND, IOR, XOR, ASHIFT,
  2609.    ASHIFTRT, and LSHIFTRT instructions set the condition codes usefully.
  2610.    Also, we assume that jumps, moves and sCOND don't affect the condition
  2611.    codes.  All else clobbers the condition codes, by assumption.
  2612.  
  2613.    We assume that ALL integer add, minus, etc. instructions effect the
  2614.    condition codes.  This MUST be consistent with i386.md.
  2615.  
  2616.    We don't record any float test or compare - the redundant test &
  2617.    compare check in final.c does not handle stack-like regs correctly. */
  2618.  
  2619. void
  2620. notice_update_cc (exp)
  2621.      rtx exp;
  2622. {
  2623.   if (GET_CODE (exp) == SET)
  2624.     {
  2625.       /* Jumps do not alter the cc's.  */
  2626.       if (SET_DEST (exp) == pc_rtx)
  2627.     return;
  2628.       /* Moving register or memory into a register:
  2629.      it doesn't alter the cc's, but it might invalidate
  2630.      the RTX's which we remember the cc's came from.
  2631.      (Note that moving a constant 0 or 1 MAY set the cc's).  */
  2632.       if (REG_P (SET_DEST (exp))
  2633.       && (REG_P (SET_SRC (exp)) || GET_CODE (SET_SRC (exp)) == MEM
  2634.           || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'))
  2635.     {
  2636.       if (cc_status.value1
  2637.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1))
  2638.         cc_status.value1 = 0;
  2639.       if (cc_status.value2
  2640.           && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2))
  2641.         cc_status.value2 = 0;
  2642.       return;
  2643.     }
  2644.       /* Moving register into memory doesn't alter the cc's.
  2645.      It may invalidate the RTX's which we remember the cc's came from.  */
  2646.       if (GET_CODE (SET_DEST (exp)) == MEM
  2647.       && (REG_P (SET_SRC (exp))
  2648.           || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<'))
  2649.     {
  2650.       if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM)
  2651.         cc_status.value1 = 0;
  2652.       if (cc_status.value2 && GET_CODE (cc_status.value2) == MEM)
  2653.         cc_status.value2 = 0;
  2654.       return;
  2655.     }
  2656.       /* Function calls clobber the cc's.  */
  2657.       else if (GET_CODE (SET_SRC (exp)) == CALL)
  2658.     {
  2659.       CC_STATUS_INIT;
  2660.       return;
  2661.     }
  2662.       /* Tests and compares set the cc's in predictable ways.  */
  2663.       else if (SET_DEST (exp) == cc0_rtx)
  2664.     {
  2665.       CC_STATUS_INIT;
  2666.       cc_status.value1 = SET_SRC (exp);
  2667.       return;
  2668.     }
  2669.       /* Certain instructions effect the condition codes. */
  2670.       else if (GET_MODE (SET_SRC (exp)) == SImode
  2671.            || GET_MODE (SET_SRC (exp)) == HImode
  2672.            || GET_MODE (SET_SRC (exp)) == QImode)
  2673.     switch (GET_CODE (SET_SRC (exp)))
  2674.       {
  2675.       case ASHIFTRT: case LSHIFTRT:
  2676.       case ASHIFT:
  2677.         /* Shifts on the 386 don't set the condition codes if the
  2678.            shift count is zero. */
  2679.         if (GET_CODE (XEXP (SET_SRC (exp), 1)) != CONST_INT)
  2680.           {
  2681.         CC_STATUS_INIT;
  2682.         break;
  2683.           }
  2684.         /* We assume that the CONST_INT is non-zero (this rtx would
  2685.            have been deleted if it were zero. */
  2686.  
  2687.       case PLUS: case MINUS: case NEG:
  2688.       case AND: case IOR: case XOR:
  2689.         cc_status.flags = CC_NO_OVERFLOW;
  2690.         cc_status.value1 = SET_SRC (exp);
  2691.         cc_status.value2 = SET_DEST (exp);
  2692.         break;
  2693.  
  2694.       default:
  2695.         CC_STATUS_INIT;
  2696.       }
  2697.       else
  2698.     {
  2699.       CC_STATUS_INIT;
  2700.     }
  2701.     }
  2702.   else if (GET_CODE (exp) == PARALLEL
  2703.        && GET_CODE (XVECEXP (exp, 0, 0)) == SET)
  2704.     {
  2705.       if (SET_DEST (XVECEXP (exp, 0, 0)) == pc_rtx)
  2706.     return;
  2707.       if (SET_DEST (XVECEXP (exp, 0, 0)) == cc0_rtx)
  2708.     {
  2709.       CC_STATUS_INIT;
  2710.       if (stack_regs_mentioned_p (SET_SRC (XVECEXP (exp, 0, 0))))
  2711.         cc_status.flags |= CC_IN_80387;
  2712.       else
  2713.         cc_status.value1 = SET_SRC (XVECEXP (exp, 0, 0));
  2714.       return;
  2715.     }
  2716.       CC_STATUS_INIT;
  2717.     }
  2718.   else
  2719.     {
  2720.       CC_STATUS_INIT;
  2721.     }
  2722. }
  2723.  
  2724. /* Split one or more DImode RTL references into pairs of SImode
  2725.    references.  The RTL can be REG, offsettable MEM, integer constant, or
  2726.    CONST_DOUBLE.  "operands" is a pointer to an array of DImode RTL to
  2727.    split and "num" is its length.  lo_half and hi_half are output arrays
  2728.    that parallel "operands". */
  2729.  
  2730. void
  2731. split_di (operands, num, lo_half, hi_half)
  2732.      rtx operands[];
  2733.      int num;
  2734.      rtx lo_half[], hi_half[];
  2735. {
  2736.   while (num--)
  2737.     {
  2738.       if (GET_CODE (operands[num]) == REG)
  2739.     {
  2740.       lo_half[num] = gen_rtx (REG, SImode, REGNO (operands[num]));
  2741.       hi_half[num] = gen_rtx (REG, SImode, REGNO (operands[num]) + 1);
  2742.     }
  2743.       else if (CONSTANT_P (operands[num]))
  2744.     {
  2745.       split_double (operands[num], &lo_half[num], &hi_half[num]);
  2746.     }
  2747.       else if (offsettable_memref_p (operands[num]))
  2748.     {
  2749.       lo_half[num] = operands[num];
  2750.       hi_half[num] = adj_offsettable_operand (operands[num], 4);
  2751.     }
  2752.       else
  2753.     abort();
  2754.     }
  2755. }
  2756.  
  2757. /* Return 1 if this is a valid binary operation on a 387.
  2758.    OP is the expression matched, and MODE is its mode. */
  2759.  
  2760. int
  2761. binary_387_op (op, mode)
  2762.     register rtx op;
  2763.     enum machine_mode mode;
  2764. {
  2765.   if (mode != VOIDmode && mode != GET_MODE (op))
  2766.     return 0;
  2767.  
  2768.   switch (GET_CODE (op))
  2769.     {
  2770.     case PLUS:
  2771.     case MINUS:
  2772.     case MULT:
  2773.     case DIV:
  2774.       return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT;
  2775.  
  2776.     default:
  2777.       return 0;
  2778.     }
  2779. }
  2780.  
  2781.  
  2782. /* Return 1 if this is a valid shift or rotate operation on a 386.
  2783.    OP is the expression matched, and MODE is its mode. */
  2784.  
  2785. int
  2786. shift_op (op, mode)
  2787.     register rtx op;
  2788.     enum machine_mode mode;
  2789. {
  2790.   rtx operand = XEXP (op, 0);
  2791.  
  2792.   if (mode != VOIDmode && mode != GET_MODE (op))
  2793.     return 0;
  2794.  
  2795.   if (GET_MODE (operand) != GET_MODE (op)
  2796.       || GET_MODE_CLASS (GET_MODE (op)) != MODE_INT)
  2797.     return 0;
  2798.  
  2799.   return (GET_CODE (op) == ASHIFT
  2800.       || GET_CODE (op) == ASHIFTRT
  2801.       || GET_CODE (op) == LSHIFTRT
  2802.       || GET_CODE (op) == ROTATE
  2803.       || GET_CODE (op) == ROTATERT);
  2804. }
  2805.  
  2806. /* Return 1 if OP is COMPARE rtx with mode VOIDmode.
  2807.    MODE is not used.  */
  2808.  
  2809. int
  2810. VOIDmode_compare_op (op, mode)
  2811.     register rtx op;
  2812.     enum machine_mode mode;
  2813. {
  2814.   return GET_CODE (op) == COMPARE && GET_MODE (op) == VOIDmode;
  2815. }
  2816.  
  2817. /* Output code to perform a 387 binary operation in INSN, one of PLUS,
  2818.    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
  2819.    is the expression of the binary operation.  The output may either be
  2820.    emitted here, or returned to the caller, like all output_* functions.
  2821.  
  2822.    There is no guarantee that the operands are the same mode, as they
  2823.    might be within FLOAT or FLOAT_EXTEND expressions. */
  2824.  
  2825. char *
  2826. output_387_binary_op (insn, operands)
  2827.      rtx insn;
  2828.      rtx *operands;
  2829. {
  2830.   rtx temp;
  2831.   char *base_op;
  2832.   static char buf[100];
  2833.  
  2834.   switch (GET_CODE (operands[3]))
  2835.     {
  2836.     case PLUS:
  2837.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  2838.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  2839.     base_op = "fiadd";
  2840.       else
  2841.     base_op = "fadd";
  2842.       break;
  2843.  
  2844.     case MINUS:
  2845.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  2846.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  2847.     base_op = "fisub";
  2848.       else
  2849.     base_op = "fsub";
  2850.       break;
  2851.  
  2852.     case MULT:
  2853.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  2854.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  2855.     base_op = "fimul";
  2856.       else
  2857.     base_op = "fmul";
  2858.       break;
  2859.  
  2860.     case DIV:
  2861.       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
  2862.       || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
  2863.     base_op = "fidiv";
  2864.       else
  2865.     base_op = "fdiv";
  2866.       break;
  2867.  
  2868.     default:
  2869.       abort ();
  2870.     }
  2871.  
  2872.   strcpy (buf, base_op);
  2873.  
  2874.   switch (GET_CODE (operands[3]))
  2875.     {
  2876.     case MULT:
  2877.     case PLUS:
  2878.       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
  2879.     {
  2880.       temp = operands[2];
  2881.       operands[2] = operands[1];
  2882.       operands[1] = temp;
  2883.     }
  2884.  
  2885.       if (GET_CODE (operands[2]) == MEM)
  2886.     return strcat (buf, AS1 (%z2,%2));
  2887.  
  2888.       if (NON_STACK_REG_P (operands[1]))
  2889.     {
  2890.       output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1)));
  2891.       RET;
  2892.     }
  2893.       else if (NON_STACK_REG_P (operands[2]))
  2894.     {
  2895.       output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1)));
  2896.       RET;
  2897.     }
  2898.  
  2899.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
  2900.     return strcat (buf, AS2 (p,%2,%0));
  2901.  
  2902.       if (STACK_TOP_P (operands[0]))
  2903.     return strcat (buf, AS2C (%y2,%0));
  2904.       else
  2905.     return strcat (buf, AS2C (%2,%0));
  2906.  
  2907.     case MINUS:
  2908.     case DIV:
  2909.       if (GET_CODE (operands[1]) == MEM)
  2910.     return strcat (buf, AS1 (r%z1,%1));
  2911.  
  2912.       if (GET_CODE (operands[2]) == MEM)
  2913.     return strcat (buf, AS1 (%z2,%2));
  2914.  
  2915.       if (NON_STACK_REG_P (operands[1]))
  2916.     {
  2917.       output_op_from_reg (operands[1], strcat (buf, AS1 (r%z0,%1)));
  2918.       RET;
  2919.     }
  2920.       else if (NON_STACK_REG_P (operands[2]))
  2921.     {
  2922.       output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1)));
  2923.       RET;
  2924.     }
  2925.  
  2926.       if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2]))
  2927.     abort ();
  2928.  
  2929.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
  2930.     return strcat (buf, AS2 (rp,%2,%0));
  2931.  
  2932.       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
  2933.     return strcat (buf, AS2 (p,%1,%0));
  2934.  
  2935.       if (STACK_TOP_P (operands[0]))
  2936.     {
  2937.       if (STACK_TOP_P (operands[1]))
  2938.         return strcat (buf, AS2C (%y2,%0));
  2939.       else
  2940.         return strcat (buf, AS2 (r,%y1,%0));
  2941.     }
  2942.       else if (STACK_TOP_P (operands[1]))
  2943.     return strcat (buf, AS2C (%1,%0));
  2944.       else
  2945.     return strcat (buf, AS2 (r,%2,%0));
  2946.  
  2947.     default:
  2948.       abort ();
  2949.     }
  2950. }
  2951.  
  2952. /* Output code for INSN to convert a float to a signed int.  OPERANDS
  2953.    are the insn operands.  The output may be SFmode or DFmode and the
  2954.    input operand may be SImode or DImode.  As a special case, make sure
  2955.    that the 387 stack top dies if the output mode is DImode, because the
  2956.    hardware requires this.  */
  2957.  
  2958. char *
  2959. output_fix_trunc (insn, operands)
  2960.      rtx insn;
  2961.      rtx *operands;
  2962. {
  2963.   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
  2964.   rtx xops[2];
  2965.  
  2966.   if (! STACK_TOP_P (operands[1]) ||
  2967.       (GET_MODE (operands[0]) == DImode && ! stack_top_dies))
  2968.     abort ();
  2969.  
  2970.   xops[0] = GEN_INT (12);
  2971.   xops[1] = operands[4];
  2972.  
  2973.   output_asm_insn (AS1 (fnstc%W2,%2), operands);
  2974.   output_asm_insn (AS2 (mov%L2,%2,%4), operands);
  2975.   output_asm_insn (AS2 (mov%B1,%0,%h1), xops);
  2976.   output_asm_insn (AS2 (mov%L4,%4,%3), operands);
  2977.   output_asm_insn (AS1 (fldc%W3,%3), operands);
  2978.  
  2979.   if (NON_STACK_REG_P (operands[0]))
  2980.     output_to_reg (operands[0], stack_top_dies);
  2981.   else if (GET_CODE (operands[0]) == MEM)
  2982.     {
  2983.       if (stack_top_dies)
  2984.     output_asm_insn (AS1 (fistp%z0,%0), operands);
  2985.       else
  2986.     output_asm_insn (AS1 (fist%z0,%0), operands);
  2987.     }
  2988.   else
  2989.     abort ();
  2990.  
  2991.   return AS1 (fldc%W2,%2);
  2992. }
  2993.  
  2994. /* Output code for INSN to compare OPERANDS.  The two operands might
  2995.    not have the same mode: one might be within a FLOAT or FLOAT_EXTEND
  2996.    expression.  If the compare is in mode CCFPEQmode, use an opcode that
  2997.    will not fault if a qNaN is present. */
  2998.  
  2999. char *
  3000. output_float_compare (insn, operands)
  3001.      rtx insn;
  3002.      rtx *operands;
  3003. {
  3004.   int stack_top_dies;
  3005.   rtx body = XVECEXP (PATTERN (insn), 0, 0);
  3006.   int unordered_compare = GET_MODE (SET_SRC (body)) == CCFPEQmode;
  3007.  
  3008.   if (! STACK_TOP_P (operands[0]))
  3009.     abort ();
  3010.  
  3011.   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
  3012.  
  3013.   if (STACK_REG_P (operands[1])
  3014.       && stack_top_dies
  3015.       && find_regno_note (insn, REG_DEAD, REGNO (operands[1]))
  3016.       && REGNO (operands[1]) != FIRST_STACK_REG)
  3017.     {
  3018.       /* If both the top of the 387 stack dies, and the other operand
  3019.      is also a stack register that dies, then this must be a
  3020.      `fcompp' float compare */
  3021.  
  3022.       if (unordered_compare)
  3023.     output_asm_insn ("fucompp", operands);
  3024.       else
  3025.     output_asm_insn ("fcompp", operands);
  3026.     }
  3027.   else
  3028.     {
  3029.       static char buf[100];
  3030.  
  3031.       /* Decide if this is the integer or float compare opcode, or the
  3032.      unordered float compare. */
  3033.  
  3034.       if (unordered_compare)
  3035.     strcpy (buf, "fucom");
  3036.       else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_FLOAT)
  3037.     strcpy (buf, "fcom");
  3038.       else
  3039.     strcpy (buf, "ficom");
  3040.  
  3041.       /* Modify the opcode if the 387 stack is to be popped. */
  3042.  
  3043.       if (stack_top_dies)
  3044.     strcat (buf, "p");
  3045.  
  3046.       if (NON_STACK_REG_P (operands[1]))
  3047.     output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1)));
  3048.       else
  3049.         output_asm_insn (strcat (buf, AS1 (%z1,%y1)), operands);
  3050.     }
  3051.  
  3052.   /* Now retrieve the condition code. */
  3053.  
  3054.   return output_fp_cc0_set (insn);
  3055. }
  3056.  
  3057. /* Output opcodes to transfer the results of FP compare or test INSN
  3058.    from the FPU to the CPU flags.  If TARGET_IEEE_FP, ensure that if the
  3059.    result of the compare or test is unordered, no comparison operator
  3060.    succeeds except NE.  Return an output template, if any.  */
  3061.  
  3062. char *
  3063. output_fp_cc0_set (insn)
  3064.      rtx insn;
  3065. {
  3066.   rtx xops[3];
  3067.   rtx unordered_label;
  3068.   rtx next;
  3069.   enum rtx_code code;
  3070.  
  3071.   xops[0] = gen_rtx (REG, HImode, 0);
  3072.   output_asm_insn (AS1 (fnsts%W0,%0), xops);
  3073.  
  3074.   if (! TARGET_IEEE_FP)
  3075.     return "sahf";
  3076.  
  3077.   next = next_cc0_user (insn);
  3078.   if (next == NULL_RTX)
  3079.     abort ();
  3080.  
  3081.   if (GET_CODE (next) == JUMP_INSN
  3082.       && GET_CODE (PATTERN (next)) == SET
  3083.       && SET_DEST (PATTERN (next)) == pc_rtx
  3084.       && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE)
  3085.     {
  3086.       code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0));
  3087.     }
  3088.   else if (GET_CODE (PATTERN (next)) == SET)
  3089.     {
  3090.       code = GET_CODE (SET_SRC (PATTERN (next)));
  3091.     }
  3092.   else
  3093.     abort ();
  3094.  
  3095.   xops[0] = gen_rtx (REG, QImode, 0);
  3096.  
  3097.   switch (code)
  3098.     {
  3099.     case GT:
  3100.       xops[1] = GEN_INT (0x45);
  3101.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3102.       /* je label */
  3103.       break;
  3104.  
  3105.     case LT:
  3106.       xops[1] = GEN_INT (0x45);
  3107.       xops[2] = GEN_INT (0x01);
  3108.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3109.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3110.       /* je label */
  3111.       break;
  3112.  
  3113.     case GE:
  3114.       xops[1] = GEN_INT (0x05);
  3115.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3116.       /* je label */
  3117.       break;
  3118.  
  3119.     case LE:
  3120.       xops[1] = GEN_INT (0x45);
  3121.       xops[2] = GEN_INT (0x40);
  3122.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3123.       output_asm_insn (AS1 (dec%B0,%h0), xops);
  3124.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3125.       /* jb label */
  3126.       break;
  3127.  
  3128.     case EQ:
  3129.       xops[1] = GEN_INT (0x45);
  3130.       xops[2] = GEN_INT (0x40);
  3131.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3132.       output_asm_insn (AS2 (cmp%B0,%2,%h0), xops);
  3133.       /* je label */
  3134.       break;
  3135.  
  3136.     case NE:
  3137.       xops[1] = GEN_INT (0x44);
  3138.       xops[2] = GEN_INT (0x40);
  3139.       output_asm_insn (AS2 (and%B0,%1,%h0), xops);
  3140.       output_asm_insn (AS2 (xor%B0,%2,%h0), xops);
  3141.       /* jne label */
  3142.       break;
  3143.  
  3144.     case GTU:
  3145.     case LTU:
  3146.     case GEU:
  3147.     case LEU:
  3148.     default:
  3149.       abort ();
  3150.     }
  3151.   RET;
  3152. }
  3153.  
  3154. #define MAX_386_STACK_LOCALS 2
  3155.  
  3156. static rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
  3157.  
  3158. /* Define the structure for the machine field in struct function.  */
  3159. struct machine_function
  3160. {
  3161.   rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS];
  3162. };
  3163.  
  3164. /* Functions to save and restore i386_stack_locals.
  3165.    These will be called, via pointer variables,
  3166.    from push_function_context and pop_function_context.  */
  3167.  
  3168. void
  3169. save_386_machine_status (p)
  3170.      struct function *p;
  3171. {
  3172.   p->machine = (struct machine_function *) xmalloc (sizeof i386_stack_locals);
  3173.   bcopy ((char *) i386_stack_locals, (char *) p->machine->i386_stack_locals,
  3174.      sizeof i386_stack_locals);
  3175. }
  3176.  
  3177. void
  3178. restore_386_machine_status (p)
  3179.      struct function *p;
  3180. {
  3181.   bcopy ((char *) p->machine->i386_stack_locals, (char *) i386_stack_locals,
  3182.      sizeof i386_stack_locals);
  3183.   free (p->machine);
  3184. }
  3185.  
  3186. /* Clear stack slot assignments remembered from previous functions.
  3187.    This is called from INIT_EXPANDERS once before RTL is emitted for each
  3188.    function.  */
  3189.  
  3190. void
  3191. clear_386_stack_locals ()
  3192. {
  3193.   enum machine_mode mode;
  3194.   int n;
  3195.  
  3196.   for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE;
  3197.        mode = (enum machine_mode) ((int) mode + 1))
  3198.     for (n = 0; n < MAX_386_STACK_LOCALS; n++)
  3199.       i386_stack_locals[(int) mode][n] = NULL_RTX;
  3200.  
  3201.   /* Arrange to save and restore i386_stack_locals around nested functions.  */
  3202.   save_machine_status = save_386_machine_status;
  3203.   restore_machine_status = restore_386_machine_status;
  3204. }
  3205.  
  3206. /* Return a MEM corresponding to a stack slot with mode MODE.
  3207.    Allocate a new slot if necessary.
  3208.  
  3209.    The RTL for a function can have several slots available: N is
  3210.    which slot to use.  */
  3211.  
  3212. rtx
  3213. assign_386_stack_local (mode, n)
  3214.      enum machine_mode mode;
  3215.      int n;
  3216. {
  3217.   if (n < 0 || n >= MAX_386_STACK_LOCALS)
  3218.     abort ();
  3219.  
  3220.   if (i386_stack_locals[(int) mode][n] == NULL_RTX)
  3221.     i386_stack_locals[(int) mode][n]
  3222.       = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
  3223.  
  3224.   return i386_stack_locals[(int) mode][n];
  3225. }
  3226.